Skip to content

Massively optimize inactive-users script by caching API safe-states #337

Description

@jagdish-15

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

  1. The script should read and maintain a new local JSON file (e.g., data/activity-state.json).
  2. 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.
  3. 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.
  4. If they don't have a safeUntil date, or the date has expired, fetch the actual profile via fetchData.
  5. Look at their submissionCalendar to find the latest timestamp.
  6. Calculate their new safeUntil boundary: latestTimestamp + (90 days). Save this back into the activity-state cache.
  7. 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!

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions