Skip to content

fix(metrics): include timezone in cache keys for timezone-sensitive endpoints#2781

Open
0xPyxis wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
0xPyxis:fix-2716-timezone-cache-keys
Open

fix(metrics): include timezone in cache keys for timezone-sensitive endpoints#2781
0xPyxis wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
0xPyxis:fix-2716-timezone-cache-keys

Conversation

@0xPyxis

@0xPyxis 0xPyxis commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Fixes a timezone-related caching bug in metrics endpoints.

Closes #2716


Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup (no functional change)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🧪 Tests only

What Changed

  • Added timezone to the cache key parameters in src/app/api/metrics/contributions/route.ts
  • Added timeZone to the cache key parameters in src/app/api/metrics/streak/route.ts
  • Added timeZone to the cache key parameters in src/app/api/metrics/consistency-score/route.ts
  • Scoped the consistency score cache by timezone to prevent stale cross-timezone cache hits

How to Test

  1. Set the dashboard timezone to one timezone (e.g. Asia/Kolkata) and load Contributions, Streak, or Consistency Score metrics.
  2. Change the timezone preference to another timezone (e.g. America/New_York).
  3. Reload the metrics endpoints.

Expected result:

Metrics should be recalculated or fetched from a timezone-specific cache entry instead of reusing data generated for a different timezone.


Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Additional Context

The cache keys previously omitted timezone information, causing timezone-sensitive metrics to be reused across different timezone settings. This change ensures cache entries are properly scoped per timezone.

@github-actions

Copy link
Copy Markdown

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!

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) and removed gssoc26 GSSoC 2026 contribution labels Jun 24, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

timeZone = "UTC",
): Promise<Set<string>> {
const key = metricsCacheKey(cacheContext.userId, "streak", { githubLogin });
const key = metricsCacheKey(cacheContext.userId, "streak", {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a WHY comment here.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

Good catch on the timezone cache key bug — this is a legitimate fix. Two things before merge:

  1. Indentation bug in consistency-score/route.ts — the replacement line has zero indentation instead of the original 2-space indent:

    -  const key = `metrics:${cacheContext.userId}:consistency-score:${cacheContext.accountKey}`;
    +const key = `metrics:${cacheContext.userId}:consistency-score:${cacheContext.accountKey}:${timeZone}`;

    Should be 2-space indented to match the surrounding code.

  2. Labels — please remove type:feature and type:performance labels. This is a pure bug fix.

Fix the indentation and this is good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Timezone parameters ignored on cache hits in Contributions, Streak, and Consistency Score endpoints

3 participants