Serve the daily players chart from a per-day totals table - #30
Merged
Conversation
Counting PlayerDay rows per day meant a sequential scan of every monthly partition, so the home page's all-time range took ages. No index could have helped: Postgres has no index-skip-scan for aggregates, so even a covering index still walks every entry. Add a GlobalDay table holding one row per rolled-up day, written inside the rollup transaction and backfilled by the migration, and read it from the chart, the status page, and the backfill worker's rolled-up-day scan, which ran the same unfiltered groupBy on every tick. The API response now carries Cache-Control, so switching back to a range already viewed is served from the browser cache. Chart labels take the year once the range needs it: MMM d, then MMM d, yyyy across a year boundary, then MMM yyyy past a year. They are built from the UTC calendar day, which also fixes every label rendering a day early west of Greenwich. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Counting
PlayerDayrows per day meant a sequential scan of every monthly partition, so the home page's all-time range took ages — and no index could have helped, since Postgres has no index-skip-scan for aggregates. This adds aGlobalDaytable holding one row per rolled-up day, written inside the rollup transaction and backfilled by the migration, then reads it from the chart, the status page, and the backfill worker's rolled-up-day scan (which ran the same unfilteredgroupByon every tick). The API response now carriesCache-Control, so switching back to a range already viewed is served from the browser cache. Chart labels take the year once the range needs one —MMM d, thenMMM d, yyyyacross a year boundary, thenMMM yyyypast a year — and are built from the UTC calendar day, which also fixes every label rendering a day early west of Greenwich. Verified against a local replica seeded with 1231 days: every range now serves in 5–8 ms.🤖 Generated with Claude Code