Description
processTimeframe() in scripts/sync-leaderboard.js computes each user's period delta via plain subtraction with no floor at zero. If a user's cumulative LeetCode totals ever read lower than the previous snapshot, the leaderboard displays a negative count and negative score for that period.
Steps to Reproduce
- Run
sync-leaderboard.js to produce a baseline daily.json snapshot for a user.
- Simulate a lower
easySolved/mediumSolved/hardSolved value on the next sync for that same user (e.g. via a temporary API glitch, or by manually editing the previous snapshot's data to be smaller before the next sync run).
- Run the sync again and inspect the resulting
daily.json/weekly.json/monthly.json.
Expected Behavior
Period deltas should never go below zero, a user can't "unsolve" problems, so the displayed progress for that period should floor at 0.
Actual Behavior
The score and per-difficulty counts go negative and are rendered as-is (e.g. -3) on the leaderboard.
Root Cause
data[i].data.easySolved -= previousData[previousIndex].data.easySolved;
data[i].data.mediumSolved -= previousData[previousIndex].data.mediumSolved;
data[i].data.hardSolved -= previousData[previousIndex].data.hardSolved;
data[i].score =
data[i].data.easySolved +
data[i].data.mediumSolved * 3 +
data[i].data.hardSolved * 5;
No Math.max(0, ...) guard, unlike equivalent delta logic elsewhere in the codebase (historical-graphs.js, compare.js) which already clamps correctly.
Suggested Fix
data[i].data.easySolved = Math.max(0, data[i].data.easySolved - previousData[previousIndex].data.easySolved);
data[i].data.mediumSolved = Math.max(0, data[i].data.mediumSolved - previousData[previousIndex].data.mediumSolved);
data[i].data.hardSolved = Math.max(0, data[i].data.hardSolved - previousData[previousIndex].data.hardSolved);
Affected Files
scripts/sync-leaderboard.js
Description
processTimeframe()inscripts/sync-leaderboard.jscomputes each user's period delta via plain subtraction with no floor at zero. If a user's cumulative LeetCode totals ever read lower than the previous snapshot, the leaderboard displays a negative count and negative score for that period.Steps to Reproduce
sync-leaderboard.jsto produce a baselinedaily.jsonsnapshot for a user.easySolved/mediumSolved/hardSolvedvalue on the next sync for that same user (e.g. via a temporary API glitch, or by manually editing the previous snapshot's data to be smaller before the next sync run).daily.json/weekly.json/monthly.json.Expected Behavior
Period deltas should never go below zero, a user can't "unsolve" problems, so the displayed progress for that period should floor at 0.
Actual Behavior
The score and per-difficulty counts go negative and are rendered as-is (e.g.
-3) on the leaderboard.Root Cause
No
Math.max(0, ...)guard, unlike equivalent delta logic elsewhere in the codebase (historical-graphs.js,compare.js) which already clamps correctly.Suggested Fix
Affected Files
scripts/sync-leaderboard.js