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