feat(leaderboard): async cache refresh via cron endpoint#1962
Conversation
|
@ask-z4ch is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
Adds refreshLeaderboardCache() to src/lib/leaderboard.ts, a new GET /api/leaderboard/refresh cron endpoint with CRON_SECRET Bearer auth, and rewrites the GET handler to cache-only flow. Closes Priyanshu-byte-coder#1799.
0100512 to
47cea17
Compare
|
Updated the branch to resolve CI failures. Root cause: the branch was based on an older Fix: rebased onto latest @Priyanshu-byte-coder could you mark this as
|
|
The 4 Playwright failures are pre-existing - all in |
|
The 4 Playwright failures are pre-existing - all in
All fail at the same step: Core CI (type-check, lint, build, dependency audit) all pass. This looks like a CI environment issue rather than a code regression. Happy to open a separate issue to track and fix this if you'd like — it affects all PRs and adds noise to reviews. |
f4be1c3
into
Priyanshu-byte-coder:main
|
🎉 Merged! Thanks for contributing to DevTrack. If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers. Keep an eye on open issues for your next contribution! |
Purpose & Rationale
The leaderboard GET endpoint rebuilt the full leaderboard on every cache miss, creating a thundering-herd risk across serverless instances and forcing users to wait for a slow synchronous build. A separate cron endpoint allows async cache refreshes independent of user-facing requests.
Technical Resolution Details
Added
refreshLeaderboardCache()tosrc/lib/leaderboard.tsthat builds the leaderboard and writes to both in-memory and Upstash caches. Createdsrc/app/api/leaderboard/refresh/route.ts- a cron endpoint withCRON_SECRETBearer auth matching the existing discord-sync pattern. Rewrote the GET handler insrc/app/api/leaderboard/route.tsto a pure cache lookup chain (memory → fresh Upstash → stale with stale-until header → 503), removing the on-demandbuildLeaderboard()call and the distributed lock. Closes #1799.Local Testing Execution
npm run type-check- 0 errorsnpm run lint- 0 new warningsnpx vitest run test/leaderboard-*- 39/39 leaderboard tests passnpm test- full suite: 1081/1092 pass (same 11 pre-existing failures, 0 new regressions)Desired Review Feedback Type
Correctness of the cache-only GET flow, especially the stale-until header calculation and error-path behaviour when both caches are empty.
Integrity & AI Usage Disclosure
In compliance with the GSSoC 2026 AI Conduct rules, I disclose that AI tools were used solely as learning and boilerplate aids. The final logic was fully reviewed, tested, and manually adapted to match human styling and clean-code design.