Skip to content

Fix commit search pagination in contributions metrics#399

Open
drb101005 wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
drb101005:fix/contribution-search-pagination
Open

Fix commit search pagination in contributions metrics#399
drb101005 wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
drb101005:fix/contribution-search-pagination

Conversation

@drb101005
Copy link
Copy Markdown

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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 19, 2026

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

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

@drb101005 drb101005 left a comment

Choose a reason for hiding this comment

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

Seen and made the changes

Copy link
Copy Markdown
Owner

@Priyanshu-byte-coder Priyanshu-byte-coder left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner

@Priyanshu-byte-coder Priyanshu-byte-coder left a comment

Choose a reason for hiding this comment

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

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants