fix(db): add LIMITs to unbounded queries to prevent OOM

Added LIMIT clauses to 4 unbounded queries that were causing
acb-index-builder to crash with OOMKill after copying web assets:

- fetchPredictorStats: LIMIT 100 (was loading all predictor stats)
- fetchMaps: LIMIT 500 (was loading all maps)
- fetchSeasonSnapshots: LIMIT 1000 (was loading all season snapshots)
- fetchSeasons: LIMIT 100 (was loading all seasons)

These queries had ORDER BY but no LIMIT, causing them to load
massive datasets into memory on each build cycle, leading to
container OOM after the web asset copy phase.

Fixes bead bf-2ws
This commit is contained in:
jedarden 2026-06-25 00:27:21 -04:00
parent 1832ff439b
commit 8736098423

View file

@ -568,6 +568,7 @@ func fetchSeasons(ctx context.Context, db *sql.DB) ([]SeasonData, error) {
FROM seasons s
LEFT JOIN bots b ON s.champion_id = b.bot_id
ORDER BY s.starts_at DESC
LIMIT 100
`
rows, err := db.QueryContext(ctx, query)
@ -644,6 +645,7 @@ func fetchSeasonSnapshots(ctx context.Context, db *sql.DB, seasonID int64) ([]Se
JOIN bots b ON ss.bot_id = b.bot_id
WHERE ss.season_id = $1
ORDER BY ss.rank
LIMIT 1000
`, seasonID)
if err != nil {
return nil, err
@ -755,6 +757,7 @@ func fetchPredictorStats(ctx context.Context, db *sql.DB) ([]PredictorStats, err
SELECT predictor_id, correct, incorrect, streak, best_streak
FROM predictor_stats
ORDER BY (correct::float / NULLIF(correct + incorrect, 0)) DESC NULLS LAST
LIMIT 100
`
rows, err := db.QueryContext(ctx, query)
@ -788,6 +791,7 @@ func fetchMaps(ctx context.Context, db *sql.DB) ([]MapData, error) {
) v ON m.map_id = v.map_id
WHERE m.status IN ('active', 'probation', 'classic')
ORDER BY m.engagement DESC
LIMIT 500
`
rows, err := db.QueryContext(ctx, query)