fix(client-runtime): branch list no longer resets while paging through refs (#5858)
This commit is contained in:
1 parent
9e61d0f127
commit
c7b14a8666
1 file changed
+22
-19
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user