fix(db): add LIMIT to pair frequency query to prevent OOMKill in acb-index-builder
The fetchOpenPredictions function had an unbounded query building a pair frequency map for rivalry detection. With thousands of bots and matches, this could return tens of thousands of rows and cause OOMKill. - Add ORDER BY COUNT(*) DESC to prioritize most common pairings - Add LIMIT 1000 - sufficient to detect rivalries (pairs with >= 3 matches) This fixes the 45-day CrashLoopBackOff with 4700+ restarts. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
bbe5f45ac1
commit
0449606ac7
1 changed files with 4 additions and 0 deletions
|
|
@ -912,6 +912,8 @@ func fetchOpenPredictions(ctx context.Context, db *sql.DB) ([]OpenPredictionMatc
|
|||
}
|
||||
|
||||
// Build pair frequency map for rivalry detection (count completed h2h matches)
|
||||
// LIMIT to most common pairings to prevent OOMKill - we only need enough
|
||||
// to detect rivalries (typically < 100 pairs have >= 3 matches)
|
||||
pairFrequency := make(map[string]int)
|
||||
freqRows, err := db.QueryContext(ctx, `
|
||||
SELECT mp1.bot_id, mp2.bot_id, COUNT(*)
|
||||
|
|
@ -920,6 +922,8 @@ func fetchOpenPredictions(ctx context.Context, db *sql.DB) ([]OpenPredictionMatc
|
|||
JOIN match_participants mp2 ON m.match_id = mp2.match_id AND mp2.player_slot = 1
|
||||
WHERE m.status = 'completed'
|
||||
GROUP BY mp1.bot_id, mp2.bot_id
|
||||
ORDER BY COUNT(*) DESC
|
||||
LIMIT 1000
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query pair frequency: %w", err)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue