Skip to content

Commit 275b042

Browse files
authored
chore(remove_app_and_related_data_task): Revert _delete_app_workflow_node_executions (#20278)
Signed-off-by: -LAN- <laipz8200@outlook.com>
1 parent 4c4887c commit 275b042

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

api/tasks/remove_app_and_related_data_task.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44

55
import click
66
from celery import shared_task # type: ignore
7-
from sqlalchemy import delete, select
7+
from sqlalchemy import delete
88
from sqlalchemy.exc import SQLAlchemyError
9-
from sqlalchemy.orm import Session
109

11-
from core.repositories import SQLAlchemyWorkflowNodeExecutionRepository
1210
from extensions.ext_database import db
1311
from models import (
14-
Account,
1512
ApiToken,
16-
App,
1713
AppAnnotationHitHistory,
1814
AppAnnotationSetting,
1915
AppDatasetJoin,
@@ -34,7 +30,7 @@
3430
)
3531
from models.tools import WorkflowToolProvider
3632
from models.web import PinnedConversation, SavedMessage
37-
from models.workflow import ConversationVariable, Workflow, WorkflowAppLog, WorkflowRun
33+
from models.workflow import ConversationVariable, Workflow, WorkflowAppLog, WorkflowNodeExecution, WorkflowRun
3834

3935

4036
@shared_task(queue="app_deletion", bind=True, max_retries=3)
@@ -191,30 +187,17 @@ def del_workflow_run(workflow_run_id: str):
191187

192188

193189
def _delete_app_workflow_node_executions(tenant_id: str, app_id: str):
194-
# Get app's owner
195-
with Session(db.engine, expire_on_commit=False) as session:
196-
stmt = select(Account).where(Account.id == App.created_by).where(App.id == app_id)
197-
user = session.scalar(stmt)
198-
199-
if user is None:
200-
errmsg = (
201-
f"Failed to delete workflow node executions for tenant {tenant_id} and app {app_id}, app's owner not found"
190+
def del_workflow_node_execution(workflow_node_execution_id: str):
191+
db.session.query(WorkflowNodeExecution).filter(WorkflowNodeExecution.id == workflow_node_execution_id).delete(
192+
synchronize_session=False
202193
)
203-
logging.error(errmsg)
204-
raise ValueError(errmsg)
205-
206-
# Create a repository instance for WorkflowNodeExecution
207-
repository = SQLAlchemyWorkflowNodeExecutionRepository(
208-
session_factory=db.engine,
209-
user=user,
210-
app_id=app_id,
211-
triggered_from=None,
212-
)
213-
214-
# Use the clear method to delete all records for this tenant_id and app_id
215-
repository.clear()
216194

217-
logging.info(click.style(f"Deleted workflow node executions for tenant {tenant_id} and app {app_id}", fg="green"))
195+
_delete_records(
196+
"""select id from workflow_node_executions where tenant_id=:tenant_id and app_id=:app_id limit 1000""",
197+
{"tenant_id": tenant_id, "app_id": app_id},
198+
del_workflow_node_execution,
199+
"workflow node execution",
200+
)
218201

219202

220203
def _delete_app_workflow_app_logs(tenant_id: str, app_id: str):

0 commit comments

Comments
 (0)