@@ -13,7 +13,11 @@ import * as Layer from "effect/Layer";
1313import * as ProcessRunner from "../processRunner.ts" ;
1414
1515const DEFAULT_REPOSITORY_IDENTITY_CACHE_CAPACITY = 512 ;
16- const DEFAULT_POSITIVE_CACHE_TTL = Duration . minutes ( 1 ) ;
16+ // Background sweeps resolve every project each minute. A long TTL keeps them
17+ // from spawning git each time. Clone, publish, and PR discovery (after a turn
18+ // and before it saves links) resolve with `refresh: true`.
19+ const DEFAULT_POSITIVE_CACHE_TTL = Duration . minutes ( 15 ) ;
20+ // Short, so a folder that gains a repository or a remote shows up quickly.
1721const DEFAULT_NEGATIVE_CACHE_TTL = Duration . minutes ( 1 ) ;
1822
1923export interface RepositoryIdentityResolverOptions {
@@ -142,20 +146,23 @@ export const make = Effect.fn("RepositoryIdentityResolver.make")(function* (
142146 const processRunner = yield * ProcessRunner . ProcessRunner ;
143147 const cacheCapacity = options . cacheCapacity ?? DEFAULT_REPOSITORY_IDENTITY_CACHE_CAPACITY ;
144148 const refine = options . refine ?? Effect . succeed ;
149+ // Git errors and timeouts resolve to null, so they use the negative TTL like
150+ // "no repository" or "no remote". Only interrupts and defects skip the cache.
151+ const timeToLive = ( exit : Exit . Exit < unknown > ) =>
152+ Exit . match ( exit , {
153+ onSuccess : ( value ) =>
154+ value === null
155+ ? ( options . negativeCacheTtl ?? DEFAULT_NEGATIVE_CACHE_TTL )
156+ : ( options . positiveCacheTtl ?? DEFAULT_POSITIVE_CACHE_TTL ) ,
157+ onFailure : ( ) => Duration . zero ,
158+ } ) ;
145159
146160 const repositoryRootCache = yield * Cache . makeWith < string , string | null > (
147161 ( cwd ) =>
148162 resolveRepositoryIdentityCacheKey ( cwd ) . pipe (
149163 Effect . provideService ( ProcessRunner . ProcessRunner , processRunner ) ,
150164 ) ,
151- {
152- capacity : cacheCapacity ,
153- timeToLive : Exit . match ( {
154- onSuccess : ( value ) =>
155- value === null ? Duration . zero : ( options . positiveCacheTtl ?? DEFAULT_POSITIVE_CACHE_TTL ) ,
156- onFailure : ( ) => Duration . zero ,
157- } ) ,
158- } ,
165+ { capacity : cacheCapacity , timeToLive } ,
159166 ) ;
160167
161168 const repositoryIdentityCache = yield * Cache . makeWith < string , RepositoryIdentity | null > (
@@ -167,27 +174,20 @@ export const make = Effect.fn("RepositoryIdentityResolver.make")(function* (
167174 ( identity ) => refine ( identity ) . pipe ( Effect . orElseSucceed ( ( ) => identity ) ) ,
168175 ) ,
169176 ) ,
170- {
171- capacity : cacheCapacity ,
172- timeToLive : Exit . match ( {
173- onSuccess : ( value ) =>
174- value === null
175- ? ( options . negativeCacheTtl ?? DEFAULT_NEGATIVE_CACHE_TTL )
176- : ( options . positiveCacheTtl ?? DEFAULT_POSITIVE_CACHE_TTL ) ,
177- onFailure : ( ) => Duration . zero ,
178- } ) ,
179- } ,
177+ { capacity : cacheCapacity , timeToLive } ,
180178 ) ;
181179
182- const resolve : RepositoryIdentityResolver [ "Service" ] [ "resolve" ] = Effect . fn (
183- "RepositoryIdentityResolver.resolve" ,
184- ) ( function * ( cwd , options ) {
185- if ( options ?. refresh ) yield * Cache . invalidate ( repositoryRootCache , cwd ) ;
186- const cacheKey = yield * Cache . get ( repositoryRootCache , cwd ) ;
187- if ( cacheKey === null ) return null ;
188- if ( options ?. refresh ) yield * Cache . invalidate ( repositoryIdentityCache , cacheKey ) ;
189- return yield * Cache . get ( repositoryIdentityCache , cacheKey ) ;
190- } ) ;
180+ // Untraced because almost every call is a cache hit. The lookups that spawn
181+ // git keep their own spans.
182+ const resolve : RepositoryIdentityResolver [ "Service" ] [ "resolve" ] = Effect . fnUntraced (
183+ function * ( cwd , options ) {
184+ if ( options ?. refresh ) yield * Cache . invalidate ( repositoryRootCache , cwd ) ;
185+ const cacheKey = yield * Cache . get ( repositoryRootCache , cwd ) ;
186+ if ( cacheKey === null ) return null ;
187+ if ( options ?. refresh ) yield * Cache . invalidate ( repositoryIdentityCache , cacheKey ) ;
188+ return yield * Cache . get ( repositoryIdentityCache , cacheKey ) ;
189+ } ,
190+ ) ;
191191
192192 return RepositoryIdentityResolver . of ( { resolve } ) ;
193193} ) ;
0 commit comments