mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor: remove final async blocking query
This commit is contained in:
@@ -4,6 +4,7 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
from uuid import uuid4
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.base import DbOper
|
||||
@@ -66,6 +67,25 @@ class AgentTaskOper(DbOper):
|
||||
return query(self._db)
|
||||
return run_sync_transaction(query)
|
||||
|
||||
async def async_get(
|
||||
self,
|
||||
task_id: int,
|
||||
user_id: Optional[str] = None,
|
||||
) -> Optional[AgentTask]:
|
||||
"""通过异步会话查询单个 Agent 定时任务。"""
|
||||
async def query(session: AsyncSession) -> Optional[AgentTask]:
|
||||
"""在调用方异步会话中执行与同步入口相同的查询语义。"""
|
||||
result = await session.execute(
|
||||
_get_for_user_statement(
|
||||
AgentTask,
|
||||
task_id=task_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
)
|
||||
return result.scalars().first()
|
||||
|
||||
return await self._execute_async_query(query)
|
||||
|
||||
def list(
|
||||
self,
|
||||
user_id: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user