Problem Description
Currently, when a user accesses a student's analytics profile, the server triggers the /api/student/:username endpoint, calling the fetchStudentHistory function in scripts/fetch-student-info.js.
To generate a 365-day graph, this function fetches daily JSON snapshots directly from the raw GitHub contents of the data repository (leetcode-ranking-data) via fetch() in chunks of 100 requests.
This leads to several critical issues:
- Excessive Network Requests: Up to 365 HTTP requests are dispatched to
raw.githubusercontent.com for a single page view.
- GitHub API Rate Limiting: The server will quickly get rate-limited by GitHub when multiple profiles are viewed.
- High Latency: Loading the profile page takes several seconds due to network roundtrips.
- Memory Leak Risk: The in-memory
studentCache in server.js is unbounded, meaning its size grows indefinitely as different usernames are queried.
Proposed Solution
- Server-side Cache Persistence: Store the compiled student histories in a local file-based cache or a lightweight database (e.g., SQLite) on the Express backend server.
- Incremental Sync: Instead of scanning 365 historical files on every request, fetch the full history once, and then only poll/fetch incremental new daily files during synchronization, appending them to the cached record.
- Bounded Cache: Implement a size limit or LRU (Least Recently Used) cache strategy for
studentCache inside server.js to automatically evict stale entries and prevent memory growth.
- Alternative - Pre-Compiled History Files: Compile the unified history of each student into a single JSON file (e.g.,
history/username.json) in the data repository during the scheduled synchronization cron job. The backend can then fetch one file instead of hundreds.
Affected Files
server.js
scripts/fetch-student-info.js
scripts/sync-leaderboard.js
Problem Description
Currently, when a user accesses a student's analytics profile, the server triggers the
/api/student/:usernameendpoint, calling thefetchStudentHistoryfunction inscripts/fetch-student-info.js.To generate a 365-day graph, this function fetches daily JSON snapshots directly from the raw GitHub contents of the data repository (
leetcode-ranking-data) viafetch()in chunks of 100 requests.This leads to several critical issues:
raw.githubusercontent.comfor a single page view.studentCacheinserver.jsis unbounded, meaning its size grows indefinitely as different usernames are queried.Proposed Solution
studentCacheinsideserver.jsto automatically evict stale entries and prevent memory growth.history/username.json) in the data repository during the scheduled synchronization cron job. The backend can then fetch one file instead of hundreds.Affected Files
server.jsscripts/fetch-student-info.jsscripts/sync-leaderboard.js