Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: optimize query for expired workflow runs by adding date filter and limiting results (#16491)

Yeuoly1907d2a90aea
diff --git a/api/services/clear_free_plan_tenant_expired_logs.py b/api/services/clear_free_plan_tenant_expired_logs.py
index 25cad92e14c..5762bf9600a 100644
--- a/api/services/clear_free_plan_tenant_expired_logs.py
+++ b/api/services/clear_free_plan_tenant_expired_logs.py
@@ -149,7 +149,15 @@ class ClearFreePlanTenantExpiredLogs:
while True:
with Session(db.engine).no_autoflush as session:
- workflow_runs = session.query(WorkflowRun).filter(WorkflowRun.tenant_id == tenant_id).all()
+ workflow_runs = (
+ session.query(WorkflowRun)
+ .filter(
+ WorkflowRun.tenant_id == tenant_id,
+ WorkflowRun.created_at < datetime.datetime.now() - datetime.timedelta(days=days),
+ )
+ .limit(batch)
+ .all()
+ )
if len(workflow_runs) == 0:
break