Summary
The streak calculation has a hardcoded 90-day look-back window. Any user whose current or longest streak exceeds 90 days will see a wrong (truncated) streak value with no warning. This also means the "Longest Streak" stat is unreliable for any dedicated contributor.
Root Cause
In src/app/api/metrics/streak/route.ts, fetchActiveDates hardcodes the search window to 90 days:
const since = new Date();
since.setDate(since.getDate() - 90);
This is also duplicated in the GET handler itself:
const since = new Date();
since.setDate(since.getDate() - 90);
const sinceStr = since.toISOString().slice(0, 10);
calculateStreakFromDates then operates only on the dates returned within this window. If a user has been committing every day for 120 days:
- The actual streak is 120 days
- The returned
activeDates only covers the last 90 days
current is reported as 90 (or less if today/yesterday falls outside)
longest is capped at whatever run exists within the 90-day slice
The same 90-day cap exists in the public profile API (src/app/api/public/[username]/route.ts, fetchStreak function), meaning public-facing profiles also display wrong streaks.
The leaderboard (src/app/api/leaderboard/route.ts) uses streakStart = toDateStr(new Date(Date.now() - 90 * 86400000)) for the same reason — leaderboard streak rankings are therefore incorrect for top contributors.
Impact
- Users with long streaks see demoralizing, incorrect numbers
- Leaderboard streak rankings are wrong for the most active users (the ones most likely to have streaks >90 days)
- No error or caveat is shown to the user — the number looks authoritative
Expected Behaviour
The look-back window for streak calculation should extend far enough to capture any realistic streak. A sensible approach: fetch up to 365 days of history (the GitHub Search API supports date ranges up to a year), or use a configurable STREAK_LOOKBACK_DAYS constant. The current/longest streak values should always reflect real history.
Proposed Fix
- Introduce a constant
STREAK_LOOKBACK_DAYS = 365 in src/app/api/metrics/streak/route.ts
- Replace all hardcoded
90 references in the streak route, the public profile route, and the leaderboard route with this constant
- Adjust the cache TTL if needed since a larger window will return more data
Labels
bug advanced ~3h
Please assign this to me under GSSoC
Summary
The streak calculation has a hardcoded 90-day look-back window. Any user whose current or longest streak exceeds 90 days will see a wrong (truncated) streak value with no warning. This also means the "Longest Streak" stat is unreliable for any dedicated contributor.
Root Cause
In
src/app/api/metrics/streak/route.ts,fetchActiveDateshardcodes the search window to 90 days:This is also duplicated in the
GEThandler itself:calculateStreakFromDatesthen operates only on the dates returned within this window. If a user has been committing every day for 120 days:activeDatesonly covers the last 90 dayscurrentis reported as 90 (or less if today/yesterday falls outside)longestis capped at whatever run exists within the 90-day sliceThe same 90-day cap exists in the public profile API (
src/app/api/public/[username]/route.ts,fetchStreakfunction), meaning public-facing profiles also display wrong streaks.The leaderboard (
src/app/api/leaderboard/route.ts) usesstreakStart = toDateStr(new Date(Date.now() - 90 * 86400000))for the same reason — leaderboard streak rankings are therefore incorrect for top contributors.Impact
Expected Behaviour
The look-back window for streak calculation should extend far enough to capture any realistic streak. A sensible approach: fetch up to 365 days of history (the GitHub Search API supports date ranges up to a year), or use a configurable
STREAK_LOOKBACK_DAYSconstant. The current/longest streak values should always reflect real history.Proposed Fix
STREAK_LOOKBACK_DAYS = 365insrc/app/api/metrics/streak/route.ts90references in the streak route, the public profile route, and the leaderboard route with this constantLabels
bugadvanced~3hPlease assign this to me under GSSoC