Skip to content

Bug: User profile XP and GitHub contribution data fetched on every page render, no caching #774

Description

@anshul23102

Bug Report: GitHub API Called on Every Component Mount Causes Rate Limit Errors

Description

The User Profile page fetches live GitHub contribution data (commits, PRs, stars)
from the GitHub REST API every time the component mounts. GitHub's unauthenticated
API allows only 60 requests per hour per IP. In a shared network environment
(office, university campus) or when multiple users visit profile pages in quick
succession, the app exhausts the GitHub API rate limit. All subsequent users
see empty contribution graphs or an error state.

Steps to Reproduce

  1. Open the DevPath User Profile page for any GitHub-connected user.
  2. Refresh the page 60 times in under 1 hour (or simulate with a script).
  3. Observe the 61st request returns HTTP 403 with X-RateLimit-Remaining: 0.
  4. All profile pages show empty contribution data until the hourly window resets.

Root Cause

The GitHub API call is made in a useEffect with no SWR/React Query caching,
no server-side caching, and no authenticated token to use the higher 5,000
req/hour limit.

Impact

The platform becomes degraded for all users on shared networks during peak
usage periods, which is precisely when a developer community platform sees
the most traffic.

Proposed Fix

Cache GitHub data server-side in Firestore with a 1-hour TTL:

// app/api/github-stats/route.ts
export async function GET(req: Request) {
  const { username } = Object.fromEntries(new URL(req.url).searchParams);
  const cacheDoc = await db.collection("github_cache").doc(username).get();
  if (cacheDoc.exists && Date.now() - cacheDoc.data()!.fetchedAt < 3600_000) {
    return Response.json(cacheDoc.data()!.stats);
  }
  const stats = await fetchGitHubStats(username, process.env.GITHUB_TOKEN);
  await db.collection("github_cache").doc(username).set({ stats, fetchedAt: Date.now() });
  return Response.json(stats);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions