use single run_id query nodeExecution

This commit is contained in:
hjlarry 2026-01-21 09:30:28 +08:00
parent 4864076b43
commit 6d23f8a071
2 changed files with 4 additions and 29 deletions

View File

@ -355,31 +355,13 @@ class DifyAPISQLAlchemyWorkflowNodeExecutionRepository(DifyAPIWorkflowNodeExecut
@staticmethod
def get_by_run(
session: Session,
run: RunContext,
run_id: str,
) -> Sequence[WorkflowNodeExecutionModel]:
"""
Fetch node executions for a run using the composite index on
(tenant_id, app_id, workflow_id, triggered_from, workflow_run_id).
Fetch node executions for a run using workflow_run_id.
"""
tuple_values = [
(
run["tenant_id"],
run["app_id"],
run["workflow_id"],
DifyAPISQLAlchemyWorkflowNodeExecutionRepository._map_run_triggered_from_to_node_triggered_from(
run["triggered_from"]
),
run["run_id"],
)
]
stmt = select(WorkflowNodeExecutionModel).where(
tuple_(
WorkflowNodeExecutionModel.tenant_id,
WorkflowNodeExecutionModel.app_id,
WorkflowNodeExecutionModel.workflow_id,
WorkflowNodeExecutionModel.triggered_from,
WorkflowNodeExecutionModel.workflow_run_id,
).in_(tuple_values)
WorkflowNodeExecutionModel.workflow_run_id == run_id
)
return list(session.scalars(stmt))

View File

@ -431,14 +431,7 @@ class WorkflowRunArchiver:
repo = self._get_workflow_run_repo()
app_logs = repo.get_app_logs_by_run_id(session, run.id)
table_data["workflow_app_logs"] = [self._row_to_dict(row) for row in app_logs]
run_context: DifyAPISQLAlchemyWorkflowNodeExecutionRepository.RunContext = {
"run_id": run.id,
"tenant_id": run.tenant_id,
"app_id": run.app_id,
"workflow_id": run.workflow_id,
"triggered_from": run.triggered_from,
}
node_exec_records = DifyAPISQLAlchemyWorkflowNodeExecutionRepository.get_by_run(session, run_context)
node_exec_records = DifyAPISQLAlchemyWorkflowNodeExecutionRepository.get_by_run(session, run.id)
node_exec_ids = [record.id for record in node_exec_records]
offload_records = DifyAPISQLAlchemyWorkflowNodeExecutionRepository.get_offloads_by_execution_ids(
session,