@@ -20,11 +20,15 @@ import { createReference } from '../../../git/models/reference';
2020import type { GitRemote } from '../../../git/models/remote' ;
2121import type { Repository , RepositoryChangeEvent } from '../../../git/models/repository' ;
2222import { RepositoryChange , RepositoryChangeComparisonMode } from '../../../git/models/repository' ;
23+ import type { GitWorktree } from '../../../git/models/worktree' ;
2324import { getWorktreeForBranch } from '../../../git/models/worktree' ;
2425import { parseGitRemoteUrl } from '../../../git/parsers/remoteParser' ;
2526import type { RichRemoteProvider } from '../../../git/remotes/richRemoteProvider' ;
2627import { executeCommand , registerCommand } from '../../../system/command' ;
2728import { debug } from '../../../system/decorators/log' ;
29+ import { Logger } from '../../../system/logger' ;
30+ import { getLogScope } from '../../../system/logger.scope' ;
31+ import { PageableResult } from '../../../system/paging' ;
2832import { getSettledValue } from '../../../system/promise' ;
2933import type { IpcMessage } from '../../../webviews/protocol' ;
3034import { onIpc } from '../../../webviews/protocol' ;
@@ -541,22 +545,30 @@ export class FocusWebviewProvider implements WebviewProvider<State> {
541545 richRepos : RepoWithRichRemote [ ] ,
542546 force ?: boolean ,
543547 ) : Promise < SearchedPullRequestWithRemote [ ] > {
548+ const scope = getLogScope ( ) ;
549+
544550 if ( force || this . _pullRequests == null ) {
545551 const allPrs : SearchedPullRequestWithRemote [ ] = [ ] ;
546- for ( const richRepo of richRepos ) {
547- const remote = richRepo . remote ;
548- const prs = await this . container . git . getMyPullRequests ( remote ) ;
549- if ( prs == null ) {
550- continue ;
552+
553+ const branchesByRepo = new Map < Repository , PageableResult < GitBranch > > ( ) ;
554+ const worktreesByRepo = new Map < Repository , GitWorktree [ ] > ( ) ;
555+
556+ const queries = richRepos . map ( r => [ r , this . container . git . getMyPullRequests ( r . remote ) ] as const ) ;
557+ for ( const [ r , query ] of queries ) {
558+ let prs ;
559+ try {
560+ prs = await query ;
561+ } catch ( ex ) {
562+ Logger . error ( ex , scope , `Failed to get prs for '${ r . remote . url } '` ) ;
551563 }
564+ if ( prs == null ) continue ;
552565
553566 for ( const pr of prs ) {
554- if ( pr . reasons . length === 0 ) {
555- continue ;
556- }
567+ if ( pr . reasons . length === 0 ) continue ;
568+
557569 const entry : SearchedPullRequestWithRemote = {
558570 ...pr ,
559- repoAndRemote : richRepo ,
571+ repoAndRemote : r ,
560572 isCurrentWorktree : false ,
561573 isCurrentBranch : false ,
562574 rank : getPrRank ( pr ) ,
@@ -566,15 +578,32 @@ export class FocusWebviewProvider implements WebviewProvider<State> {
566578 entry . pullRequest . refs ! . head . branch
567579 } `; // TODO@eamodio really need to check for upstream url rather than name
568580
581+ let branches = branchesByRepo . get ( entry . repoAndRemote . repo ) ;
582+ if ( branches == null ) {
583+ branches = new PageableResult < GitBranch > ( paging =>
584+ entry . repoAndRemote . repo . getBranches ( paging != null ? { paging : paging } : undefined ) ,
585+ ) ;
586+ branchesByRepo . set ( entry . repoAndRemote . repo , branches ) ;
587+ }
588+
589+ let worktrees = worktreesByRepo . get ( entry . repoAndRemote . repo ) ;
590+ if ( worktrees == null ) {
591+ worktrees = await entry . repoAndRemote . repo . getWorktrees ( ) ;
592+ worktreesByRepo . set ( entry . repoAndRemote . repo , worktrees ) ;
593+ }
594+
569595 const worktree = await getWorktreeForBranch (
570596 entry . repoAndRemote . repo ,
571597 entry . pullRequest . refs ! . head . branch ,
572598 remoteBranchName ,
599+ worktrees ,
600+ branches ,
573601 ) ;
602+
574603 entry . hasWorktree = worktree != null ;
575604 entry . isCurrentWorktree = worktree ?. opened === true ;
576605
577- const branch = await getLocalBranchByUpstream ( richRepo . repo , remoteBranchName ) ;
606+ const branch = await getLocalBranchByUpstream ( r . repo , remoteBranchName , branches ) ;
578607 if ( branch ) {
579608 entry . branch = branch ;
580609 entry . hasLocalBranch = true ;
@@ -601,22 +630,27 @@ export class FocusWebviewProvider implements WebviewProvider<State> {
601630
602631 @debug ( { args : { 0 : false } } )
603632 private async getMyIssues ( richRepos : RepoWithRichRemote [ ] , force ?: boolean ) : Promise < SearchedIssueWithRank [ ] > {
633+ const scope = getLogScope ( ) ;
634+
604635 if ( force || this . _pullRequests == null ) {
605636 const allIssues = [ ] ;
606- for ( const richRepo of richRepos ) {
607- const remote = richRepo . remote ;
608- const issues = await this . container . git . getMyIssues ( remote ) ;
609- if ( issues == null ) {
610- continue ;
637+
638+ const queries = richRepos . map ( r => [ r , this . container . git . getMyIssues ( r . remote ) ] as const ) ;
639+ for ( const [ r , query ] of queries ) {
640+ let issues ;
641+ try {
642+ issues = await query ;
643+ } catch ( ex ) {
644+ Logger . error ( ex , scope , `Failed to get issues for '${ r . remote . url } '` ) ;
611645 }
646+ if ( issues == null ) continue ;
612647
613648 for ( const issue of issues ) {
614- if ( issue . reasons . length === 0 ) {
615- continue ;
616- }
649+ if ( issue . reasons . length === 0 ) continue ;
650+
617651 allIssues . push ( {
618652 ...issue ,
619- repoAndRemote : richRepo ,
653+ repoAndRemote : r ,
620654 rank : 0 , // getIssueRank(issue),
621655 } ) ;
622656 }
0 commit comments