Repository navigation
Batch the merged-PR lookup in disk-cleanup's worktrees module - #269
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
disk-cleanup --module worktreesmade onegh pr listcall 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
-fvariables, so a branch name can't break the query and a branch named123stays 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,
ghexits 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.shpasses (93 assertions) under/bin/bash3.2bin/disk-cleanup --module worktreeslists the same worktrees before and afterhttps://claude.ai/code/session_01AovXvZtSm7j2tCYofcpL1m