Skip to content

Batch the merged-PR lookup in disk-cleanup's worktrees module - #269

Merged
haacked merged 1 commit into
mainfrom
haacked/disk-cleanup-batch-pr-lookup
Oct 28, 2026
Merged

haacked merged 1 commit into
mainfrom
haacked/disk-cleanup-batch-pr-lookup

Conversation

@haacked

@haacked haacked commented Oct 28, 2026

Copy link
Copy Markdown
Owner

disk-cleanup --module worktrees made one gh pr list call per worktree to find merged PRs. With about 40 worktrees, those calls took up most of a 20 to 40 second run.

This looks up every worktree's merged PR in one GraphQL request, with an alias per worktree and up to 50 aliases per request. Owners, repo names, and branches go in as -f variables, so a branch name can't break the query and a branch named 123 stays a string. A PR only counts when its head repo is the worktree's own repo, which drops fork PRs that reuse the branch name.

When one repo in the request can't be resolved, such as a deleted repo, gh exits non-zero but the response still holds the other aliases. I use that response: the missing repo's worktrees report nothing and the rest get checked as usual. Otherwise one stale worktree would turn off the merged check for everything else. If a request returns no data at all, the module logs it and skips the merged-worktree check. The removal guards don't change.

On my machine a conservative run went from 21.5s to 6.7s and listed the same worktrees.

Test plan

  • bin/lib/test-cleanup-worktrees.sh passes (93 assertions) under /bin/bash 3.2
  • New tests cover fork PRs, an unresolvable repo, batching, one request per run, and failed requests
  • bin/disk-cleanup --module worktrees lists the same worktrees before and after

https://claude.ai/code/session_01AovXvZtSm7j2tCYofcpL1m

Looks up every worktree's merged PR in one GitHub GraphQL request, with
50 aliases per request, instead of one gh pr list call per worktree.
Owners, names, and branches go in as variables. Only PRs whose head repo
is the worktree's own repo count, so a fork PR that reuses the branch
name is ignored. A repo GitHub cannot resolve reports nothing, and a
request that returns no data skips the merged-worktree check.

Claude-Session: https://claude.ai/code/session_01AovXvZtSm7j2tCYofcpL1m
@haacked
haacked marked this pull request as ready for review October 28, 2026 23:35
@haacked
haacked merged commit 4f813b5 into main Oct 28, 2026
1 check passed
@haacked
haacked deleted the haacked/disk-cleanup-batch-pr-lookup branch October 28, 2026 23:36
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