From 873609842391676e9c51d746c6e6d9d65f574d42 Mon Sep 17 00:00:00 2001 From: jedarden Date: Thu, 25 Jun 2026 00:27:21 -0400 Subject: [PATCH] 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 --- cmd/acb-index-builder/db.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/acb-index-builder/db.go b/cmd/acb-index-builder/db.go index 5699af4..83db884 100644 --- a/cmd/acb-index-builder/db.go +++ b/cmd/acb-index-builder/db.go @@ -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)