@@ -930,7 +930,9 @@ export const make = Effect.gen(function* () {
930930 readonly viewer : string | null ;
931931 readonly error : PullRequestProviderError | null ;
932932 } ;
933- const viewerKey = ( host : string , scope : string ) => `${ host } \n${ scope } ` ;
933+ // Every grouping of repositories goes through this key: a group is read with one credential, so
934+ // it can share a viewer, a batched search and a line-count read without mixing two accounts.
935+ const credentialKey = ( host : string , scope : string ) => `${ host } \n${ scope } ` ;
934936 const viewersByHost = new Map < string , { readonly at : number ; readonly result : ResolvedViewer } > ( ) ;
935937 const viewerFlights = yield * Cache . makeWith (
936938 ( key : string ) : Effect . Effect < ResolvedViewer > => {
@@ -960,7 +962,7 @@ export const make = Effect.gen(function* () {
960962 } ) ) ,
961963 Effect . tap ( ( result ) =>
962964 Effect . map ( Clock . currentTimeMillis , ( at ) =>
963- viewersByHost . set ( viewerKey ( host , scope ) , { at, result } ) ,
965+ viewersByHost . set ( credentialKey ( host , scope ) , { at, result } ) ,
964966 ) ,
965967 ) ,
966968 Effect . catch ( ( error ) =>
@@ -989,15 +991,15 @@ export const make = Effect.gen(function* () {
989991 options ?: { readonly allowPaused : boolean } ,
990992 ) =>
991993 Effect . forEach (
992- [ ...new Set ( projects . map ( ( project ) => viewerKey ( project . host , project . credentialScope ) ) ) ] ,
994+ [ ...new Set ( projects . map ( ( project ) => credentialKey ( project . host , project . credentialScope ) ) ) ] ,
993995 ( accountKey ) =>
994996 Effect . flatMap ( Clock . currentTimeMillis , ( now ) : Effect . Effect < ResolvedViewer > => {
995997 const held = viewersByHost . get ( accountKey ) ;
996998 if ( held !== undefined && now - held . at <= Duration . toMillis ( VIEWER_CACHE_TTL ) ) {
997999 return Effect . succeed ( held . result ) ;
9981000 }
9991001 const forAccount = projects . filter (
1000- ( project ) => viewerKey ( project . host , project . credentialScope ) === accountKey ,
1002+ ( project ) => credentialKey ( project . host , project . credentialScope ) === accountKey ,
10011003 ) ;
10021004 const { host, api } = forAccount [ 0 ] ! ;
10031005 const scope = forAccount [ 0 ] ! . credentialScope ;
@@ -1140,11 +1142,11 @@ export const make = Effect.gen(function* () {
11401142 const viewers : Record < string , string > = { } ;
11411143 for ( const result of viewerResults ) {
11421144 if ( result . viewer === null ) continue ;
1143- viewerByAccount . set ( viewerKey ( result . host , result . scope ) , result . viewer ) ;
1145+ viewerByAccount . set ( credentialKey ( result . host , result . scope ) , result . viewer ) ;
11441146 viewers [ result . host ] ??= result . viewer ;
11451147 }
11461148 const viewerFor = ( project : SupportedProject ) : string | undefined =>
1147- viewerByAccount . get ( viewerKey ( project . host , project . credentialScope ) ) ;
1149+ viewerByAccount . get ( credentialKey ( project . host , project . credentialScope ) ) ;
11481150
11491151 const providers : ReadonlyArray < PullRequestProviderSummary > = [
11501152 ...[ ...new Set ( viewerResults . map ( ( result ) => result . host ) ) ] . map ( ( host ) => {
@@ -1192,8 +1194,8 @@ export const make = Effect.gen(function* () {
11921194 result . error === null ||
11931195 ! selected . some (
11941196 ( project ) =>
1195- viewerKey ( project . host , project . credentialScope ) ===
1196- viewerKey ( result . host , result . scope ) ,
1197+ credentialKey ( project . host , project . credentialScope ) ===
1198+ credentialKey ( result . host , result . scope ) ,
11971199 )
11981200 ? [ ]
11991201 : [ result . error ] ,
@@ -1388,7 +1390,7 @@ export const make = Effect.gen(function* () {
13881390 separate . push ( project ) ;
13891391 continue ;
13901392 }
1391- const key = `${ project . host } \n ${ viewerFor ( project ) } \n${ cursorOf ( project ) ?. updatedBefore ?? "" } ` ;
1393+ const key = `${ credentialKey ( project . host , project . credentialScope ) } \n${ cursorOf ( project ) ?. updatedBefore ?? "" } ` ;
13921394 const group = together . get ( key ) ;
13931395 if ( group === undefined ) together . set ( key , [ project ] ) ;
13941396 else group . push ( project ) ;
@@ -2423,7 +2425,7 @@ export const make = Effect.gen(function* () {
24232425 const listStatsUncached : PullRequestService [ "Service" ] [ "listStats" ] = ( input ) =>
24242426 Effect . gen ( function * ( ) {
24252427 if ( input . refs . length === 0 ) return { stats : [ ] } ;
2426- const { supported, viewerRoots } = yield * listWorkspaceProjects ( { } ) ;
2428+ const { supported } = yield * listWorkspaceProjects ( { } ) ;
24272429 const byProject = new Map ( supported . map ( ( project ) => [ project . project . id , project ] ) ) ;
24282430 const wanted = new Map <
24292431 string ,
@@ -2440,22 +2442,9 @@ export const make = Effect.gen(function* () {
24402442 }
24412443 wanted . set ( `${ project . project . id } ${ ref . number } ` , { project, number : ref . number } ) ;
24422444 }
2443- // One read carries one account's token, so rows are grouped by who the listing read them
2444- // as: the viewer the listing already resolved, or the scope where it could not.
2445- const viewerResults = yield * resolveViewers (
2446- [ ...wanted . values ( ) ] . map ( ( { project } ) => project ) ,
2447- viewerRoots ,
2448- ) ;
2449- const accountOf = ( project : SupportedProject ) => {
2450- const scope = project . credentialScope ;
2451- const viewer = viewerResults . find (
2452- ( result ) => result . host === project . host && result . scope === scope ,
2453- ) ?. viewer ;
2454- return `${ project . host } \n${ viewer == null ? `scope ${ scope } ` : `viewer ${ viewer } ` } ` ;
2455- } ;
24562445 const byAccount = new Map < string , Array < { project : SupportedProject ; number : number } > > ( ) ;
24572446 for ( const entry of wanted . values ( ) ) {
2458- const key = accountOf ( entry . project ) ;
2447+ const key = credentialKey ( entry . project . host , entry . project . credentialScope ) ;
24592448 const held = byAccount . get ( key ) ;
24602449 if ( held === undefined ) byAccount . set ( key , [ entry ] ) ;
24612450 else held . push ( entry ) ;
0 commit comments