Skip to content

Conversation

Copy link

Copilot AI commented Oct 18, 2025

Problem

Pull request counts were previously fetched sequentially, which resulted in slow performance for organizations with many repositories. Each repository had to wait for the previous one to complete before starting its API call.

For example, an organization with 100 repositories would make 100 sequential API calls, with each call waiting for the previous one to finish.

Solution

This PR implements batch processing with limited concurrency to significantly improve performance while respecting GitHub API rate limits.

Key Changes

  1. Added processPullRequestsInBatches function: A new helper function that processes repositories in configurable batches using Promise.all for concurrent fetching
  2. Updated generateBadges function: Replaced the sequential for loop with the new batch processing approach
  3. Configurable batch size: Defaults to 10 concurrent requests per batch, providing optimal balance between performance and rate limits

Implementation

Before:

for (const repo of repos) {
  const { total, merged } = await getPullRequestsCount(org, repo, prFilterDate, client);
  totalOpenPRs += total;
  totalMergedPRs += merged;
}

After:

const { totalOpenPRs, totalMergedPRs } = await processPullRequestsInBatches(
  org,
  repos,
  prFilterDate,
  client
);

The new function processes repositories in chunks of 10, with each chunk processed concurrently:

for (let i = 0; i < repos.length; i += batchSize) {
  const batch = repos.slice(i, i + batchSize);
  const results = await Promise.all(
    batch.map(repo => getPullRequestsCount(org, repo, prFilterDate, client))
  );
  // Aggregate results...
}

Performance Impact

  • 100 repositories: Reduced from 100 sequential calls to 10 batches of concurrent calls (~10x faster)
  • 250 repositories: Reduced from 250 sequential calls to 25 batches (~10x faster)

Testing

Added 5 comprehensive test cases covering:

  • Processing multiple repositories in a single batch
  • Processing repositories across multiple batches
  • Handling empty repository lists
  • Verifying default batch size behavior
  • Correct aggregation of PR counts across batches

All existing tests continue to pass, ensuring backward compatibility.

Closes #18

Original prompt

This section details on the original issue you should resolve

<issue_title>Fetch pull request counts in batches with limited concurrency</issue_title>
<issue_description>> [nitpick] Pull request counts are fetched sequentially, which can become slow for organizations with many repositories. Consider batching with limited concurrency (e.g. Promise.all on chunks) to reduce total runtime while respecting rate limits.

#18 (comment)</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #19


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 18, 2025 05:34
Co-authored-by: joshjohanning <19912012+joshjohanning@users.noreply.github.com>
Co-authored-by: joshjohanning <19912012+joshjohanning@users.noreply.github.com>
Copilot AI changed the title [WIP] Fetch pull request counts in batches with limited concurrency Fetch pull request counts in batches with limited concurrency Oct 18, 2025
Copilot AI requested a review from joshjohanning October 18, 2025 05:39
Copilot finished work on behalf of joshjohanning October 18, 2025 05:39
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.

Fetch pull request counts in batches with limited concurrency

2 participants