mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
refactor: migrate high-risk write transactions
This commit is contained in:
@@ -314,6 +314,21 @@ class AgentChatOper(DbOper):
|
||||
await AgentChat.async_delete(self._db, chat.id)
|
||||
return True
|
||||
|
||||
async def async_stage_delete(
|
||||
self,
|
||||
session_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> bool:
|
||||
"""暂存 Agent 会话删除并 flush,不提交请求级事务。"""
|
||||
if not isinstance(self._db, AsyncSession):
|
||||
raise RuntimeError("Agent 会话暂存删除需要调用方提供 AsyncSession")
|
||||
chat = await self.async_get(session_id=session_id, user_id=user_id)
|
||||
if not chat:
|
||||
return False
|
||||
await self._db.delete(chat)
|
||||
await self._db.flush()
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def to_summary(chat: AgentChat) -> dict[str, Any]:
|
||||
"""
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from sqlalchemy import delete
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.base import DbOper
|
||||
from app.db.models.plugindata import PluginData
|
||||
|
||||
@@ -82,6 +85,15 @@ class PluginDataOper(DbOper):
|
||||
else:
|
||||
PluginData.del_plugin_data(self._db, plugin_id)
|
||||
|
||||
def stage_delete(self, plugin_id: str) -> None:
|
||||
"""暂存目标插件全部数据删除并 flush,不提交调用方事务。"""
|
||||
if not isinstance(self._db, Session):
|
||||
raise RuntimeError("插件数据暂存删除需要调用方提供 Session")
|
||||
self._db.execute(
|
||||
delete(PluginData).where(PluginData.plugin_id == plugin_id)
|
||||
)
|
||||
self._db.flush()
|
||||
|
||||
def truncate(self):
|
||||
"""
|
||||
清空插件数据
|
||||
|
||||
Reference in New Issue
Block a user