| ... | @@ -236,29 +236,32 @@ export function cachedVcsRefsChanges( | ... | @@ -236,29 +236,32 @@ export function cachedVcsRefsChanges( |
| 236 | export function createVcsEnvironmentAtoms<R, E>( | 236 | export function createVcsEnvironmentAtoms<R, E>( |
| 237 | runtime: Atom.AtomRuntime<EnvironmentRegistry | EnvironmentCacheStore | R, E>, | 237 | runtime: Atom.AtomRuntime<EnvironmentRegistry | EnvironmentCacheStore | R, E>, |
| 238 | ) { | 238 | ) { |
| 239 | const listRefsByEnvironment = Atom.family((environmentId: EnvironmentId) => | 239 | /** |
| 240 | Atom.family((inputKey: string) => { | 240 | * One flat family on purpose: families hold entries via WeakRef, so a nested |
| 241 | const input = JSON.parse(inputKey) as VcsListRefsInput; | 241 | * per-environment family can be collected between lookups, dropping every |
| 242 | return runtime | 242 | * cached page atom and collapsing paginated ref lists mid-scroll. |
| 243 | .atom((get) => { | 243 | */ |
| 244 | const state = get(vcsRefsCacheStateAtom({ environmentId })); | 244 | const listRefsFamily = Atom.family((key: string) => { |
| 245 | return cachedVcsRefsChanges( | 245 | const [environmentId, input] = JSON.parse(key) as [EnvironmentId, VcsListRefsInput]; |
| 246 | environmentId, | 246 | return runtime |
| 247 | input, | 247 | .atom((get) => { |
| 248 | state.revision, | 248 | const state = get(vcsRefsCacheStateAtom({ environmentId })); |
| 249 | state.persistedCacheReadable, | 249 | return cachedVcsRefsChanges( |
| 250 | ); | 250 | environmentId, |
| 251 | }) | 251 | input, |
| 252 | .pipe( | 252 | state.revision, |
| 253 | Atom.setIdleTTL(VCS_REFS_IDLE_TTL_MS), | 253 | state.persistedCacheReadable, |
| 254 | Atom.withLabel(`environment-data:vcs:list-refs:${environmentId}:${inputKey}`), | | |
| 255 | ); | 254 | ); |
| 256 | }), | 255 | }) |
| 257 | ); | 256 | .pipe( |
| | 257 | Atom.setIdleTTL(VCS_REFS_IDLE_TTL_MS), |
| | 258 | Atom.withLabel(`environment-data:vcs:list-refs:${key}`), |
| | 259 | ); |
| | 260 | }); |
| 258 | const listRefs = (target: { | 261 | const listRefs = (target: { |
| 259 | readonly environmentId: EnvironmentId; | 262 | readonly environmentId: EnvironmentId; |
| 260 | readonly input: VcsListRefsInput; | 263 | readonly input: VcsListRefsInput; |
| 261 | }) => listRefsByEnvironment(target.environmentId)(JSON.stringify(target.input)); | 264 | }) => listRefsFamily(JSON.stringify([target.environmentId, target.input])); |
| 262 | const invalidateRefs = ( | 265 | const invalidateRefs = ( |
| 263 | target: { readonly environmentId: EnvironmentId; readonly input: { readonly cwd: string } }, | 266 | target: { readonly environmentId: EnvironmentId; readonly input: { readonly cwd: string } }, |
| 264 | registry: AtomRegistry.AtomRegistry, | 267 | registry: AtomRegistry.AtomRegistry, |