[Fix] #1312 Streak logic duplication resolved.#1870
Conversation
…ore logic abstracted to src/lib/streak.ts.
|
@palxsh01 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):
|
There was a problem hiding this comment.
Thanks for your first PR on DevTrack! 🎉
A maintainer will review it within 48 hours. While you wait:
- Make sure CI is passing (type-check + lint)
- Double-check the PR description is filled out and the issue is linked
- Feel free to ask questions in Discussions if you need help
If you find DevTrack useful, a ⭐ star on the repo is always appreciated — it helps the project grow and attract more contributors!
|
Branch was updated and multiple merge conflicts have arised. Resolving merge conflicts and will open a new PR for a clean merge into main. |
Summary
Extracts the duplicated streak calculation algorithm into a single shared module
at
src/lib/streak.ts, removing ~230 lines of copy-pasted logic spread across6 source files. Also fixes two sil consolidation.
Closes #1312
Type of Change
Changes Made
src/lib/streak.tsexposing two shared exports:calculateStreakFromDates(activeDates, freezeDates?)— full calculation with freeze date supportcalculateCurrentStreak(dates)— lightweight wrapper returning only the current streak numberstreak/route.ts,streak-shield/route.ts,public-profile-data.ts,compare/route.ts,leaderboard/route.ts,weekly-summary/route.tscalculateStreakFromDates.test.tsandleaderboard-streak.test.tsto import from the shared module instead of maintaining local copiescompare/route.tswherelongestStreakwas never tracked — endpoint returned only current streakstreak-shield/route.tswheredateDiffDaysusedDate.UTC()instead of ISO string truncation, causing off-by-one results for users near UTC midnightHow to Test
npm run type-check— should pass with no errorsnpm test— all 285 tests should passnpm run lint— should pass/api/metrics/streak,/api/badge/streak-shield, and/api/public/[username]return consistent streak values for the same GitHub userScreenshots (if UI change)
N/A — backend refactor only, no UI changes.
Checklist
npm run lintpasses locallynpm run type-check)Accessibility Checklist
Additional Notes
All existing tests continue to pase follows the same commentingconventions as the rest of
src/lib/— inline//comments for non-obvious constraints, a short JSDoc block on the exported function.