Repository navigation
Fix summary cold-cache timeouts and ranking query reads - #268
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The home page's summary request was repeatedly exceeding Gunicorn's 30-second deadline after a cache-version change. Every request tried to compute 42 competitions before writing any of the 34 ended-competition cache entries, so a cold cache never recovered.
Scope submission metadata before looking up public runs and secret-test eligibility. Add a partial covering index containing the run ID used for deterministic tie-breaking, so ranking queries can use index-only scans. Disable transaction-local JIT for the short ranking queries, avoiding roughly 0.5 seconds of compilation per batch. Bound ranking work to 10 seconds per request and 3 seconds per query; save completed ended-competition results immediately and roll back timed-out queries to a savepoint so competition metadata still loads. Timed-out results are never cached as empty rankings.
Production recovery already performed: rebuilt the 34 ended-competition cache entries from the current ranking query, built the covering index concurrently, and vacuumed/analyzed runs and submissions. No submissions or ranking records were changed.
Validation:
EXPLAIN (ANALYZE, BUFFERS)measured the new query at 0.85 seconds for the eight active competitions and 4.56 seconds for all 42. The public/secret run lookups used index-only scans with zero heap fetches. These measurements used warm PostgreSQL buffers, not a cold disk benchmark.The query still scales with submissions in the selected competitions. During a timeout, the page returns competition metadata with unavailable top-user lists omitted until a later request succeeds; existing completed cache entries remain available. The
use_betadiagnostic path bypasses Redis through the same bounded query implementation.