mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 02:42:59 +00:00 
			
		
		
		
	fix: optimize query for expired workflow runs by adding date filter and limiting results (#16491)
This commit is contained in:
		
							parent
							
								
									4448a54cc1
								
							
						
					
					
						commit
						1907d2a90a
					
				| @ -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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Yeuoly
						Yeuoly