Skip to content

Fix pagination termination logic and extract max pages constant#23

Merged
kertal merged 2 commits into
claude/github-issues-pagination-7Axlkfrom
copilot/sub-pr-21
Jan 10, 2026
Merged

Fix pagination termination logic and extract max pages constant#23
kertal merged 2 commits into
claude/github-issues-pagination-7Axlkfrom
copilot/sub-pr-21

Conversation

Copilot AI commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

Addresses two issues in the GitHub search pagination implementation:

Issue 1: Incorrect pagination termination

The condition page * perPage >= totalCount fails when totalCount is exactly divisible by perPage. For 200 items with perPage=100, after fetching page 2, the condition 2 * 100 >= 200 stops pagination correctly, but the logic was comparing against the wrong accumulator (allItems.length, which includes deduplicated items across all queries) instead of items fetched for the current query.

Changes:

  • Track items per query: Added itemsFetchedForQuery counter that accumulates items from the API response before deduplication
  • Fix termination condition: Changed from page * perPage >= totalCount || items.length < perPage to items.length < perPage || itemsFetchedForQuery >= totalCount
  • Extract constant: Moved maxPages = 10 to module-level GITHUB_SEARCH_API_MAX_PAGES in settings.ts for consistency with other API constants
// Before: compared against global deduplicated count
if (page * perPage >= totalCount || items.length < perPage) {
  break;
}

// After: track items fetched for current query
let itemsFetchedForQuery = 0;
// ... in fetch loop:
itemsFetchedForQuery += items.length;
if (items.length < perPage || itemsFetchedForQuery >= totalCount) {
  break;
}

The fix ensures accurate pagination for edge cases where the total count is exactly divisible by the page size.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: kertal <463851+kertal@users.noreply.github.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jan 10, 2026

Copy link
Copy Markdown

Deploying git-vegas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8f0d528
Status: ✅  Deploy successful!
Preview URL: https://a564344a.git-vegas.pages.dev
Branch Preview URL: https://copilot-sub-pr-21.git-vegas.pages.dev

View logs

Copilot AI changed the title [WIP] Add pagination support for fetching GitHub issues Fix pagination termination logic and extract max pages constant Jan 10, 2026
Copilot AI requested a review from kertal January 10, 2026 22:39
@kertal
kertal marked this pull request as ready for review January 10, 2026 22:44
@kertal
kertal merged commit e08822c into claude/github-issues-pagination-7Axlk Jan 10, 2026
1 check passed
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