Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions scripts/sync-leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,26 @@ async function computeRankChanges(currentSorted, filename) {
let previousRanks = {};
const previousData = await getYesterdaySnapshot(filename);

if (previousData && Array.isArray(previousData)) {
previousData.forEach((user, idx) => {
previousRanks[user.id] = user.originalRank || idx + 1;
// getYesterdaySnapshot() returns null on ANY error (network, GitHub API,
// rate-limit, missing commit). Falling through with an empty previousRanks
// would flag EVERY user as "NEW" below, wiping all rank arrows — and that
// gets persisted to JSON, so one transient hiccup sticks until the next clean
// run. When the snapshot is unusable, leave rank changes neutral instead of
// fabricating a board-wide "NEW".
if (!previousData || !Array.isArray(previousData)) {
console.warn(
`⚠️ No usable previous snapshot for ${filename}; leaving rank changes neutral (not marking users as NEW).`,
);
currentSorted.forEach((user) => {
user.rankChange = 0;
});
return;
}

previousData.forEach((user, idx) => {
previousRanks[user.id] = user.originalRank || idx + 1;
});

currentSorted.forEach((user, idx) => {
const currentRank = user.originalRank || idx + 1;

Expand Down
Loading