Skip to content

Commit 71b7f96

Browse files
committed
perf: bound integration.results scan in can_onboard_more (CM-1318)
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent d2a6465 commit 71b7f96

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • services/apps/mailing_list_integration/src/crowdmail/database

services/apps/mailing_list_integration/src/crowdmail/database/crud.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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}")

0 commit comments

Comments
 (0)