@@ -55,6 +55,7 @@ const STATUS_UPSTREAM_REFRESH_FAILURE_MAX_COOLDOWN = Duration.minutes(15);
5555const STATUS_UPSTREAM_REFRESH_CACHE_CAPACITY = 2_048 ;
5656const REPOSITORY_PATHS_CACHE_CAPACITY = 2_048 ;
5757const REPOSITORY_PATHS_CACHE_TTL = Duration . minutes ( 10 ) ;
58+ const REPOSITORY_PATHS_REFRESH_COALESCE_TTL = Duration . seconds ( 5 ) ;
5859const NON_REPOSITORY_PATHS_CACHE_TTL = Duration . seconds ( 1 ) ;
5960const LIST_REFS_SNAPSHOT_CACHE_CAPACITY = 64 ;
6061const LIST_REFS_SNAPSHOT_CACHE_TTL = Duration . minutes ( 2 ) ;
@@ -1085,9 +1086,27 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
10851086 } ) ,
10861087 } ,
10871088 ) ;
1089+ const repositoryPathsRefreshCache = yield * Cache . makeWith (
1090+ ( cwd : string ) =>
1091+ Cache . invalidate ( repositoryPathsCache , cwd ) . pipe (
1092+ Effect . andThen ( Cache . get ( repositoryPathsCache , cwd ) ) ,
1093+ ) ,
1094+ {
1095+ capacity : REPOSITORY_PATHS_CACHE_CAPACITY ,
1096+ timeToLive : Exit . match ( {
1097+ onSuccess : ( repositoryPaths ) =>
1098+ repositoryPaths === null
1099+ ? NON_REPOSITORY_PATHS_CACHE_TTL
1100+ : REPOSITORY_PATHS_REFRESH_COALESCE_TTL ,
1101+ onFailure : ( ) => Duration . zero ,
1102+ } ) ,
1103+ } ,
1104+ ) ;
10881105 const normalizeRepositoryPathsCacheKey = ( cwd : string ) => path . normalize ( path . resolve ( cwd ) ) ;
1089- const resolveRepositoryPaths = ( cwd : string ) =>
1090- Cache . get ( repositoryPathsCache , normalizeRepositoryPathsCacheKey ( cwd ) ) ;
1106+ const resolveRepositoryPaths = ( cwd : string , refresh = false ) => {
1107+ const cacheKey = normalizeRepositoryPathsCacheKey ( cwd ) ;
1108+ return Cache . get ( refresh ? repositoryPathsRefreshCache : repositoryPathsCache , cacheKey ) ;
1109+ } ;
10911110
10921111 const resolveGitCommonDir = Effect . fn ( "resolveGitCommonDir" ) ( function * ( cwd : string ) {
10931112 const repositoryPaths = yield * resolveRepositoryPaths ( cwd ) ;
@@ -2189,15 +2208,23 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
21892208 defaultRefResult . exitCode === 0
21902209 ? defaultRefResult . stdout . trim ( ) . replace ( / ^ r e f s \/ r e m o t e s \/ o r i g i n \/ / , "" )
21912210 : null ;
2192- const worktreeMap =
2211+ const parsedWorktreeEntries =
21932212 worktreeListResult . exitCode === 0
2194- ? new Map (
2195- [ ...parseWorktreeBranchPaths ( worktreeListResult . stdout ) ] . map (
2196- ( [ branchName , worktreePath ] ) =>
2197- [ branchName , path . normalize ( path . resolve ( worktreePath ) ) ] as const ,
2198- ) ,
2213+ ? [ ...parseWorktreeBranchPaths ( worktreeListResult . stdout ) ] . map (
2214+ ( [ branchName , worktreePath ] ) =>
2215+ [ branchName , path . normalize ( path . resolve ( worktreePath ) ) ] as const ,
21992216 )
2200- : new Map < string , string > ( ) ;
2217+ : [ ] ;
2218+ const existingWorktreeEntries = yield * Effect . filter (
2219+ parsedWorktreeEntries ,
2220+ ( [ , worktreePath ] ) =>
2221+ fileSystem . stat ( worktreePath ) . pipe (
2222+ Effect . as ( true ) ,
2223+ Effect . orElseSucceed ( ( ) => false ) ,
2224+ ) ,
2225+ { concurrency : 16 } ,
2226+ ) ;
2227+ const worktreeMap = new Map ( existingWorktreeEntries ) ;
22012228 const localBranches : Array < { readonly ref : VcsRef ; readonly lastCommit : number } > = [ ] ;
22022229 const remoteBranches : Array < { readonly ref : VcsRef ; readonly lastCommit : number } > = [ ] ;
22032230
@@ -2313,12 +2340,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
23132340 if ( repositoryPaths === null ) return ;
23142341 yield * Cache . invalidate ( listRefsRefreshSnapshotCache , repositoryPaths . gitCommonDir ) ;
23152342 bumpListRefsEpoch ( repositoryPaths . gitCommonDir ) ;
2343+ yield * Cache . invalidate ( repositoryPathsRefreshCache , repositoryPathsCacheKey ) ;
23162344 yield * Cache . invalidate ( repositoryPathsCache , repositoryPathsCacheKey ) ;
23172345 } ) ;
23182346
23192347 const listRefs : GitVcsDriver . GitVcsDriver [ "Service" ] [ "listRefs" ] = Effect . fn ( "listRefs" ) (
23202348 function * ( input ) {
2321- const repositoryPaths = yield * resolveRepositoryPaths ( input . cwd ) . pipe (
2349+ const repositoryPaths = yield * resolveRepositoryPaths ( input . cwd , input . refresh === true ) . pipe (
23222350 Effect . catchTags ( {
23232351 GitCommandError : ( error ) =>
23242352 isMissingGitCwdError ( error ) ? Effect . succeed ( null ) : Effect . fail ( error ) ,
@@ -2675,6 +2703,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26752703 input ,
26762704 ) =>
26772705 initRepo ( input ) . pipe (
2706+ Effect . tap ( ( ) =>
2707+ Cache . invalidate ( repositoryPathsRefreshCache , normalizeRepositoryPathsCacheKey ( input . cwd ) ) ,
2708+ ) ,
26782709 Effect . tap ( ( ) =>
26792710 Cache . invalidate ( repositoryPathsCache , normalizeRepositoryPathsCacheKey ( input . cwd ) ) ,
26802711 ) ,
0 commit comments