fix(db): add LIMIT to bot match stats query to prevent OOMKill

The bot match stats query was introduced in b35a2aa to fix an N+1 query
problem, but it was unbounded and could return an unlimited number of rows.
With many bots in the database, this query could consume excessive memory
and cause OOMKill, resulting in silent crashes after 'Copied web assets'.

Add LIMIT 20000 to prevent unbounded result sets while supporting large
bot populations (the main bots query already limits to 10000 bots).

This fix continues the pattern of adding LIMITs to prevent OOMKill crashes
in acb-index-builder.

Fixes bead bf-2ws: acb-index-builder CrashLoopBackOff investigation
This commit is contained in:
jedarden 2026-06-25 06:29:12 -04:00
parent b35a2aade0
commit be9a070fbb

View file

@ -346,6 +346,7 @@ func fetchBots(ctx context.Context, db *sql.DB) ([]BotData, error) {
JOIN matches m ON mp.match_id = m.match_id
WHERE m.status = 'completed'
GROUP BY mp.bot_id
LIMIT 20000
`)
if err != nil {
return nil, fmt.Errorf("query bot match stats: %w", err)