Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions packages/client-runtime/src/state/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,29 +236,32 @@ export function cachedVcsRefsChanges(
export function createVcsEnvironmentAtoms<R, E>(
runtime: Atom.AtomRuntime<EnvironmentRegistry | EnvironmentCacheStore | R, E>,
) {
const listRefsByEnvironment = Atom.family((environmentId: EnvironmentId) =>
Atom.family((inputKey: string) => {
const input = JSON.parse(inputKey) as VcsListRefsInput;
return runtime
.atom((get) => {
const state = get(vcsRefsCacheStateAtom({ environmentId }));
return cachedVcsRefsChanges(
environmentId,
input,
state.revision,
state.persistedCacheReadable,
);
})
.pipe(
Atom.setIdleTTL(VCS_REFS_IDLE_TTL_MS),
Atom.withLabel(`environment-data:vcs:list-refs:${environmentId}:${inputKey}`),
/**
* One flat family on purpose: families hold entries via WeakRef, so a nested
* per-environment family can be collected between lookups, dropping every
* cached page atom and collapsing paginated ref lists mid-scroll.
*/
const listRefsFamily = Atom.family((key: string) => {
const [environmentId, input] = JSON.parse(key) as [EnvironmentId, VcsListRefsInput];
return runtime
.atom((get) => {
const state = get(vcsRefsCacheStateAtom({ environmentId }));
return cachedVcsRefsChanges(
environmentId,
input,
state.revision,
state.persistedCacheReadable,
);
}),
);
})
.pipe(
Atom.setIdleTTL(VCS_REFS_IDLE_TTL_MS),
Atom.withLabel(`environment-data:vcs:list-refs:${key}`),
);
});
const listRefs = (target: {
readonly environmentId: EnvironmentId;
readonly input: VcsListRefsInput;
}) => listRefsByEnvironment(target.environmentId)(JSON.stringify(target.input));
}) => listRefsFamily(JSON.stringify([target.environmentId, target.input]));
const invalidateRefs = (
target: { readonly environmentId: EnvironmentId; readonly input: { readonly cwd: string } },
registry: AtomRegistry.AtomRegistry,
Expand Down
Loading