Skip to content

perf(pr)!: batch prune's merged-PR lookup into one gh call - #110

Merged
lettertwo merged 1 commit into
mainfrom
perf/prune-batch-pr-lookup
Oct 8, 2026
Merged

lettertwo merged 1 commit into
mainfrom
perf/prune-batch-pr-lookup

Conversation

@lettertwo

Copy link
Copy Markdown
Owner

workon prune spawned one gh pr list --head <branch> --state merged per signal-less row to find the PrMerged signal. Since #99 added no-worktree branches to prune's scope, that cost scales with local branch count: on a repo with 80 local branches, a dry run made 79 sequential gh calls at ~0.4s each and took ~32s.

This PR replaces the per-branch lookup with one gh api graphql request that carries an alias per branch (up to 100 per request). The same dry run now takes 1.73s and makes one api graphql call, with identical output.

  • find_merged_pr in the workon lib becomes find_merged_prs(&[&str]) -> Result<HashMap<String, MergedPr>>, which is why the commit is marked breaking.
  • Each alias asks for pullRequests(headRefName:, states:MERGED, first:1) ordered by CREATED_AT DESC, matching the newest-first PR gh pr list returned. Branch names go in as -f variables, never into the query text.
  • gh resolves {owner}/{repo} the same way gh pr list resolves its repo.
  • The 3-consecutive-failures bound is gone. A failed request now degrades every row to no signal at once, with no warning, which keeps prune's under-report-only contract.
  • The prune test stubs answer api graphql instead of pr list. The consecutive-failure tests are replaced by a test asserting one call covers every worktree and branch row, and a test asserting a failed call degrades quietly.

@lettertwo
lettertwo force-pushed the perf/prune-batch-pr-lookup branch from 6f26c44 to f45bfaf Compare October 7, 2026 18:29
@lettertwo
lettertwo force-pushed the perf/prune-batch-pr-lookup branch from f45bfaf to f9eb194 Compare October 8, 2026 02:12
@lettertwo
lettertwo merged commit 147b8c5 into main Oct 8, 2026
14 checks passed
@lettertwo
lettertwo deleted the perf/prune-batch-pr-lookup branch October 8, 2026 02:30
@github-actions github-actions Bot mentioned this pull request Oct 8, 2026
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