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

pull/14262/head
Yeuoly 1 year ago committed by Bharat Ramanathan
parent ab756bf393
commit 44c9190a77

@ -149,7 +149,15 @@ class ClearFreePlanTenantExpiredLogs:
while True: while True:
with Session(db.engine).no_autoflush as session: 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: if len(workflow_runs) == 0:
break break

Loading…
Cancel
Save