fix: recover missing daily snapshot once at sync start, so one missed day can't freeze all data (#377) - #386
Open
vedant7007 wants to merge 1 commit into
Open
Conversation
A single missing look-back snapshot (missed cron day, or <30 days of history) made processTimeframe rethrow and the top-level catch call process.exit(1) — before changes.json and the per-user update loop. So every user's history/streak/rank froze while overall.json still looked healthy. Per maintainer guidance, recover once up front instead of special-casing each timeframe: after today's snapshot is written, ensureSnapshot() checks each required look-back (1/7/30d) and, if missing, copies the latest available earlier snapshot into place with a warning. processTimeframe is left untouched — it can assume its baseline exists — so weekly/monthly logic stays simple and the sync always reaches changes.json + user updates. A fresh repo with no earlier history falls back to the current snapshot (zero deltas) rather than crashing. Closes codepvg#377
Contributor
|
Thank you for submitting a pull request. Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully. Formatting and Branching
|
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.
What & why
In
scripts/sync-leaderboard.js,processTimeframe()loads the daily snapshot from exactlydaysAgoback (1/7/30). If that one file is missing, thecatchrethrows and the top-level catch callsprocess.exit(1)— beforechanges.jsonand the entire per-user update loop. So a single missing historical snapshot (a missed cron day, or <30 days of history) means no user gets history/streak/rank updates, whileoverall.jsonis already written so the board looks healthy.Approach (per @jagdish-15's suggestion on the issue)
Recover the missing snapshot once, up front, rather than special-casing each timeframe:
ensureSnapshot(DATA_DIR, daysAgo): after today's snapshot is written, for each required look-back it checks the expecteddaily/file; if missing, it finds the latest available earlier snapshot, copies it into the missing date's filename, and logs:processTimeframeis left unchanged — it can now assume its baseline exists — keeping weekly/monthly logic simple and letting the sync always reachchanges.json+ the per-user updates.Test
Added a focused test of the selection logic covering: missing date → latest prior, present file → no-op, target older than all history → oldest available, and fresh-repo → current snapshot. All pass.
node --checkclean.Closes #377