@@ -63,28 +63,15 @@ func runStatus(gitClient git.GitClient, githubClient github.GitHubClient) error
6363 var tree * stack.TreeNode
6464 var allTreeBranches []string
6565
66- // Start fetch and PR loading in parallel with stack tree building (if not --no-pr)
67- // These are the slowest operations and can run while we build the tree
68- var wg sync.WaitGroup
66+ // Start fetch in parallel with stack tree building (if not --no-pr)
67+ var fetchWg sync.WaitGroup
6968 var prCache map [string ]* github.PRInfo
70- var prErr error
7169 fetchDone := false
7270
7371 if ! noPR {
74- wg .Add (2 )
72+ fetchWg .Add (1 )
7573 go func () {
76- defer wg .Done ()
77- prCache , prErr = githubClient .GetAllPRs ()
78- if prErr != nil {
79- if verbose {
80- fmt .Printf (" [gh] Error fetching PRs: %v\n " , prErr )
81- }
82- // If fetching fails, fall back to empty cache
83- prCache = make (map [string ]* github.PRInfo )
84- }
85- }()
86- go func () {
87- defer wg .Done ()
74+ defer fetchWg .Done ()
8875 // Fetch latest changes from origin (needed for sync issue detection)
8976 _ = gitClient .Fetch ()
9077 fetchDone = true
@@ -93,7 +80,7 @@ func runStatus(gitClient git.GitClient, githubClient github.GitHubClient) error
9380 prCache = make (map [string ]* github.PRInfo )
9481 }
9582
96- // Build the stack tree AND wait for PR fetch (runs in parallel)
83+ // Build the stack tree, then fetch PRs for tree branches only
9784 if err := spinner .WrapWithAutoDelay ("Loading stack..." , 300 * time .Millisecond , func () error {
9885 // Get current branch
9986 var err error
@@ -126,42 +113,9 @@ func runStatus(gitClient git.GitClient, githubClient github.GitHubClient) error
126113 // Get ALL branch names in the tree (including intermediate branches without stackparent)
127114 allTreeBranches = getAllBranchNamesFromTree (tree )
128115
129- // Wait for PR fetch to complete (if running )
116+ // Fetch PRs for stack branches only (parallel individual fetches )
130117 if ! noPR {
131- wg .Wait ()
132-
133- // GetAllPRs only fetches open PRs (to avoid 502 timeouts on large repos).
134- // For branches in our stack that aren't in the cache, check individually
135- // to detect merged PRs that need special handling.
136- // OPTIMIZATION: Only check branches in the current tree, not all stack branches.
137- branchSet := make (map [string ]bool )
138- for _ , name := range allTreeBranches {
139- branchSet [name ] = true
140- }
141- baseBranch := stack .GetBaseBranch (gitClient )
142-
143- for _ , branch := range stackBranches {
144- // Skip branches not in the current tree
145- if ! branchSet [branch .Name ] {
146- continue
147- }
148- // Skip if already in cache (has open PR)
149- if _ , exists := prCache [branch .Name ]; exists {
150- continue
151- }
152- // Fetch PR info for this branch (might be merged or non-existent)
153- if pr , err := githubClient .GetPRForBranch (branch .Name ); err == nil && pr != nil {
154- prCache [branch .Name ] = pr
155- }
156- // Also check parent if not in cache and not base branch
157- if branch .Parent != baseBranch {
158- if _ , exists := prCache [branch .Parent ]; ! exists {
159- if pr , err := githubClient .GetPRForBranch (branch .Parent ); err == nil && pr != nil {
160- prCache [branch .Parent ] = pr
161- }
162- }
163- }
164- }
118+ prCache = githubClient .GetPRsForBranches (allTreeBranches )
165119 }
166120
167121 return nil
@@ -170,8 +124,8 @@ func runStatus(gitClient git.GitClient, githubClient github.GitHubClient) error
170124 }
171125
172126 if len (stackBranches ) == 0 {
173- // Wait for PR fetch to complete before returning
174- wg .Wait ()
127+ // Wait for fetch to complete before returning
128+ fetchWg .Wait ()
175129 fmt .Println ("No stack branches found." )
176130 fmt .Printf ("Current branch: %s\n " , ui .Branch (currentBranch ))
177131 fmt .Printf ("\n Use '%s' to create a new stack branch.\n " , ui .Command ("stack new <branch-name>" ))
@@ -220,6 +174,9 @@ func runStatus(gitClient git.GitClient, githubClient github.GitHubClient) error
220174
221175 // Check for sync issues (skip if --no-pr)
222176 if ! noPR {
177+ // Wait for git fetch to complete (needed for sync issue detection)
178+ fetchWg .Wait ()
179+
223180 // Filter stackBranches to only include branches in the current tree
224181 branchSet := make (map [string ]bool )
225182 for _ , name := range allTreeBranches {
0 commit comments