File Name
scripts/sync-leaderboard.js
Problem
Inside processTimeframe, the script uses .findIndex() inside a loop to find previous user data:
const previousIndex = previousData.findIndex((obj) => obj.id === item.id);
Scanning an array repeatedly inside loops leads to $O(N^2)$ inefficiency as the student user base scales up.
Proposed Solution
Convert the previousData array into a Map before chunk processing to ensure $O(1)$ lookups.
File Name
scripts/sync-leaderboard.jsProblem
Inside
processTimeframe, the script uses.findIndex()inside a loop to find previous user data:Scanning an array repeatedly inside loops leads to$O(N^2)$ inefficiency as the student user base scales up.
Proposed Solution
Convert the previousData array into a Map before chunk processing to ensure$O(1)$ lookups.