File tree Expand file tree Collapse file tree
services/apps/mailing_list_integration/src/crowdmail/database Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -171,7 +171,13 @@ async def can_onboard_more() -> bool:
171171 or if the query fails (indicating high database load).
172172 """
173173 try :
174- integration_results_count = await fetchval ("SELECT COUNT(*) FROM integration.results" )
174+ # Bound the scan: integration.results holds millions of rows, and a plain
175+ # COUNT(*) walks the whole table every 5s poll tick. LIMIT lets Postgres
176+ # stop as soon as it has enough rows to answer the threshold check.
177+ integration_results_count = await fetchval (
178+ "SELECT COUNT(*) FROM (SELECT 1 FROM integration.results LIMIT $1) t" ,
179+ (MAX_INTEGRATION_RESULTS ,),
180+ )
175181 return integration_results_count < MAX_INTEGRATION_RESULTS
176182 except Exception as e :
177183 logger .warning (f"Failed to get integration.results count with error: { e } " )
You can’t perform that action at this time.
0 commit comments