The scripts/analyze-inactivity.js script currently polls the Leetcode API for every single user in our database on a daily basis to see if they've crossed a 90-day inactivity threshold.
If a user solved a problem yesterday, they are mathematically guaranteed to not become inactive for another 89 days. Polling their API during that 89-day padding window wastes massive amounts of compute time (and hits rate limits).
We need to implement a state cache tracking safeUntil timestamps for active users to completely skip unnecessary backend polling.
Implementation Requirements
- The script should read and maintain a new local JSON file (e.g.,
data/activity-state.json).
- Inside the concurrency loop, before fetching a user's
baseUrl + username data, check if activity-state.json has a safeUntil date in the future for this user.
- If
Date.now() < safeUntil, we immediately know they are active. Skip the fetchData call completely and just log them as active by continuing the iteration.
- If they don't have a
safeUntil date, or the date has expired, fetch the actual profile via fetchData.
- Look at their
submissionCalendar to find the latest timestamp.
- Calculate their new
safeUntil boundary: latestTimestamp + (90 days). Save this back into the activity-state cache.
- Save the updated
activity-state.json file at the bottom of the script alongside inactive-users.json.
Note: You must thoughtfully construct the cache structure so it doesn't lose old user tracking on subsequent runs!
The
scripts/analyze-inactivity.jsscript currently polls the Leetcode API for every single user in our database on a daily basis to see if they've crossed a 90-day inactivity threshold.If a user solved a problem yesterday, they are mathematically guaranteed to not become inactive for another 89 days. Polling their API during that 89-day padding window wastes massive amounts of compute time (and hits rate limits).
We need to implement a state cache tracking
safeUntiltimestamps for active users to completely skip unnecessary backend polling.Implementation Requirements
data/activity-state.json).baseUrl + usernamedata, check ifactivity-state.jsonhas asafeUntildate in the future for this user.Date.now() < safeUntil, we immediately know they are active. Skip thefetchDatacall completely and just log them as active by continuing the iteration.safeUntildate, or the date has expired, fetch the actual profile viafetchData.submissionCalendarto find the latest timestamp.safeUntilboundary:latestTimestamp + (90 days). Save this back into theactivity-statecache.activity-state.jsonfile at the bottom of the script alongsideinactive-users.json.Note: You must thoughtfully construct the cache structure so it doesn't lose old user tracking on subsequent runs!