Skip to content

Fix achievement rate limit#2297

Open
VIDYANKSHINI wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
VIDYANKSHINI:fix-achievement-rate-limit
Open

Fix achievement rate limit#2297
VIDYANKSHINI wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
VIDYANKSHINI:fix-achievement-rate-limit

Conversation

@VIDYANKSHINI

Copy link
Copy Markdown
Contributor

Summary

This PR resolves the GitHub Search API rate limit exhaustion bug by wrapping the /api/metrics/achievement-progress route with our Redis/Memory caching layer. The achievement progress estimator now relies on cached data instead of making a live API call on every dashboard load.

Closes #2296


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

  • src/lib/metrics-cache.ts: Added "achievement-progress" to the METRICS_CACHE_TTL_SECONDS map with a TTL of 7200 seconds (2 hours) to avoid repetitive external fetches for non-realtime historical achievements.
  • src/app/api/metrics/achievement-progress/route.ts: Refactored the route handler to pass the achievement progress fetch operation through withMetricsCache(), assigning a specific cache key using the user.id.
  • Synced and resolved upstream caching implementation conflicts with the main branch.

How to Test

  1. Check out this branch and run npm install followed by npm run dev.
  2. Navigate to the DevTrack dashboard where the AchievementProgressTracker widget is rendered.
  3. Refresh the dashboard multiple times within a short period.
  4. Verify via terminal logs or network tools that the external GitHub /search/commits or GraphQL API is not being spammed, and rate limits are not triggered.

Expected result: The achievement estimator fetches the data once and then accurately serves subsequent requests directly from the local memory / Redis cache.


Screenshots / Recordings

N/A (No visual UI changes, only backend fetching logic optimizations)


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

Accessibility (UI changes only)

N/A


Additional Context

The caching mechanism honors the standard ?refresh=true / ?bypassCache=true bypass flags. If a developer explicitly needs to re-sync achievements, they can still trigger a bypass to query the fresh data.

…limit

# Conflicts:
#	src/app/api/metrics/achievement-progress/route.ts
#	src/lib/metrics-cache.ts
Copilot AI review requested due to automatic review settings June 10, 2026 15:57
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

@VIDYANKSHINI 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.

@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) labels Jun 10, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates caching and formatting for the achievement-progress metrics endpoint.

Changes:

  • Increased achievement-progress cache TTL from 10 minutes to 2 hours.
  • Removed an invisible BOM/odd leading character from the achievement-progress API route import line.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/lib/metrics-cache.ts Adjusts cache TTL value for achievement-progress.
src/app/api/metrics/achievement-progress/route.ts Normalizes file start/import line by removing BOM/leading character.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/metrics-cache.ts
Comment on lines 19 to 23
compare: 30 * 60,
"weekly-summary": 30 * 60,
"commit-times": 30 * 60,
"achievement-progress": 10 * 60,
"achievement-progress": 7200,
} as const;
@github-actions github-actions Bot added the type:testing GSSoC type bonus: tests (+10 pts) label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] GitHub Search API Rate Limit Exhaustion due to Missing Caching in Achievement Progress Estimator

2 participants