perf: share data fetch across endpoints to avoid rate limits#4
Merged
Conversation
…te limits The pagination fix (24d6cd5) raised the per-fetch cost from 3 to up to 12 search API calls. With 4 widget endpoints fetching independently on cold start, a burst can hit ~48 search calls and trip GitHub's 30/min limit. Observed in production immediately after the fix shipped. This adds a module-level promise cache keyed by username so concurrent endpoint hits share a single in-flight fetch. Each cold-start instance now makes one fetchContributionData call per username regardless of how many endpoints are hit. The ?cache=no query param still forces a fresh fetch. Errors and rejections are not cached — next call retries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The pagination fix in #1 raised per-fetch cost from 3 to up to 12 search calls. With 4 widget endpoints (card, recent, top-repos, activity) each fetching independently on cold-start, a burst can issue ~48 search calls and trip GitHub's 30/min limit. This was observed in production minutes after the fix shipped — every endpoint returned `GitHub API rate limit reached` SVGs until the bucket reset.
This change adds a module-level promise cache keyed by username (`lib/contribution-cache.ts`). Concurrent endpoint hits share one in-flight fetch. Each cold-start instance makes one `fetchContributionData` call per username regardless of how many endpoints get hit.
Test plan