Skip to content

feat: batch PR status queries to reduce API rate limit usage#12

Merged
piotrostr merged 3 commits intomainfrom
VIB-9/replace-github-graphql-polling-with-push-based-pr-status
Jan 28, 2026
Merged

feat: batch PR status queries to reduce API rate limit usage#12
piotrostr merged 3 commits intomainfrom
VIB-9/replace-github-graphql-polling-with-push-based-pr-status

Conversation

@piotrostr
Copy link
Owner

Summary

  • Replace per-branch GraphQL polling with single batch query that fetches all open PRs at once
  • Reduces N API calls per poll interval to 1, preventing rate limit exhaustion
  • Add get_all_open_prs() function using gh api graphql with batch query
  • Match PRs to branches locally via headRefName field

Background

The app was exhausting GitHub GraphQL rate limits by making one API call per worktree branch every 30 seconds. With many worktrees, this quickly exhausted the 5000 points/hour limit.

Research findings:

  • GitHub does not support GraphQL subscriptions (no push-based updates available)
  • Webhooks require a publicly accessible server (not suitable for CLI app)
  • REST API ETags only work for REST, not GraphQL
  • Best solution: batch all PR queries into a single GraphQL request

Test plan

  • All existing tests pass
  • New tests added for GraphQL response parsing
  • Manual verification of batch query output
  • Manual testing of TUI with multiple worktrees

piotrostr and others added 3 commits January 27, 2026 23:23
Replace per-branch GraphQL polling with single batch query that fetches
all open PRs at once. This reduces N API calls per poll interval to 1.

- Add get_all_open_prs() that fetches all open PRs in single GraphQL query
- Return HashMap<branch_name, BranchPrInfo> for local matching
- Update poll_pr_info_async to use batch query instead of per-branch calls
- Add tests for GraphQL response parsing

Co-Authored-By: piotrek & opus <noreply@anthropic.com>
Batch query only costs ~2 points, so 5s interval uses ~29% of rate limit.
Much more responsive PR status updates.

Co-Authored-By: piotrek & opus <noreply@anthropic.com>
The query was only fetching OPEN PRs, so merged/closed PRs would
disappear from results and tasks would stay as "in progress".

Now fetches all states (OPEN, MERGED, CLOSED) ordered by most recently
updated.

Co-Authored-By: piotrek & opus <noreply@anthropic.com>
@piotrostr piotrostr merged commit 58f0cba into main Jan 28, 2026
2 checks 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.

1 participant