Fix commit search pagination in contributions metrics#399
Conversation
|
@drb101005 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. |
There was a problem hiding this comment.
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
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
The pagination logic is correct, but this PR removes the withMetricsCache wrapper that was added by the recently merged PR #311. Removing it breaks the Redis caching for contributions.
The pagination needs to be implemented INSIDE the withMetricsCache callback:
return withMetricsCache(
{ bypass: cacheContext.bypass, key, ttlSeconds: METRICS_CACHE_TTL_SECONDS.contributions },
async () => {
const since = new Date();
since.setDate(since.getDate() - days);
const sinceStr = toLocalDateStr(since);
let allItems: Array<{ commit: { author: { date: string } } }> = [];
let page = 1;
while (page <= 10) {
// ... pagination loop ...
if (data.items.length < 100) break;
page++;
}
const commitsByDay: Record<string, number> = {};
for (const item of allItems) { ... }
return { days, total: totalCount, data: commitsByDay };
}
);Please rebase on main (which has #311 merged) and add pagination inside the cache callback.
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Pagination logic is correct — the loop up to 10 pages with the 1000-result cap is the right approach.
Rate limit risk — up to 10 sequential GitHub Search API calls per load for high-activity users. GitHub's authenticated rate limit is 30 req/min for search. At minimum add graceful handling for 429/403 responses (currently throws a generic error). Ideally add a comment acknowledging this trade-off so future maintainers understand the risk.
Fixed inaccurate contribution metrics in route.ts by properly paginating GitHub commit search results
Added support for fetching multiple pages (per_page=100&page=N) until all available results are retrieved, the reported total count is reached, or GitHub’s 1000-result search limit is hit
Aggregated commit data across all pages before calculating contribution statistics
Improved the accuracy of total commits, active contribution days, and related contribution metrics while keeping the existing API response shape unchanged
Closes [BUG] Paginate commit search results for high-activity users #301