GeezerVison is showing github.com — fix(client-runtime): share ref refresh freshness across list keys · pingdotgg/t3code@f619a97
File treeExpand file treeCollapse file tree Open diff view settings packages/client-runtime/src/state
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.test.ts +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -209,6 +209,40 @@ describe("cached VCS refs", () => { | 209 | 209 | invalidateVcsRefs(registry, TARGET); | 210 | 210 |
| 211 | 211 | expect(yield* Queue.take(requests)).toEqual({ cwd: "/repo", limit: 100, refresh: true }); | | 212 | + | | 213 | + yield* Effect.acquireRelease( | | 214 | + Effect.sync(() => | | 215 | + registry.mount( | | 216 | + atoms.listRefs({ | | 217 | + environmentId: TARGET.environmentId, | | 218 | + input: { cwd: "/other-repo", limit: 100 }, | | 219 | + }), | | 220 | + ), | | 221 | + ), | | 222 | + (unmount) => Effect.sync(unmount), | | 223 | + ); | | 224 | + expect(yield* Queue.take(requests)).toEqual({ | | 225 | + cwd: "/other-repo", | | 226 | + limit: 100, | | 227 | + refresh: true, | | 228 | + }); | | 229 | + | | 230 | + yield* Effect.acquireRelease( | | 231 | + Effect.sync(() => | | 232 | + registry.mount( | | 233 | + atoms.listRefs({ | | 234 | + environmentId: TARGET.environmentId, | | 235 | + input: { cwd: "/other-repo", query: "release", limit: 100 }, | | 236 | + }), | | 237 | + ), | | 238 | + ), | | 239 | + (unmount) => Effect.sync(unmount), | | 240 | + ); | | 241 | + expect(yield* Queue.take(requests)).toEqual({ | | 242 | + cwd: "/other-repo", | | 243 | + query: "release", | | 244 | + limit: 100, | | 245 | + }); | 212 | 246 | }), | 213 | 247 | ), | 214 | 248 | ); | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.ts +11-10Lines changed: 11 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,6 +33,9 @@ import { | 33 | 33 | withVcsRefsPersistenceLock, | 34 | 34 | } from "./vcsRefInvalidation.ts"; | 35 | 35 |
| | 36 | +// Share freshness across search and pagination keys, but keep it local to this registry. | | 37 | +const serverRefsRevisionAtom = Atom.family((_key: string) => Atom.make(0).pipe(Atom.keepAlive)); | | 38 | + | 36 | 39 | const OFFLINE_BRANCH_LIST_LIMIT = 100; | 37 | 40 | const VCS_REFS_IDLE_TTL_MS = 30_000; | 38 | 41 | const VCS_STATUS_IDLE_TTL_MS = 10_000; | @@ -122,7 +125,6 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange | 122 | 125 | expectedRevision?: number, | 123 | 126 | registry?: AtomRegistry.AtomRegistry, | 124 | 127 | persistedCacheReadable = true, | 125 | | - bypassServerSnapshot = false, | 126 | 128 | ) { | 127 | 129 | const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor; | 128 | 130 | const cache = yield* Persistence.EnvironmentCacheStore; | @@ -144,6 +146,13 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange | 144 | 146 | ) | 145 | 147 | : Option.none<VcsListRefsResult>(); | 146 | 148 | const refresh = Effect.fn("CachedVcsRefsState.refresh")(function* () { | | 149 | + const revisionAtom = serverRefsRevisionAtom( | | 150 | + `${environmentId.length}:${environmentId}${input.cwd}`, | | 151 | + ); | | 152 | + const bypassServerSnapshot = | | 153 | + expectedRevision !== undefined && | | 154 | + registry !== undefined && | | 155 | + expectedRevision > registry.get(revisionAtom); | 147 | 156 | const refs = yield* request( | 148 | 157 | WS_METHODS.vcsListRefs, | 149 | 158 | bypassServerSnapshot ? { ...input, refresh: true } : input, | @@ -170,6 +179,7 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange | 170 | 179 | expectedRevision, | 171 | 180 | persist: useCache, | 172 | 181 | }); | | 182 | + if (committed && bypassServerSnapshot) registry.set(revisionAtom, expectedRevision); | 173 | 183 | return committed ? Option.some(refs) : Option.none<VcsListRefsResult>(); | 174 | 184 | }); | 175 | 185 |
| @@ -221,7 +231,6 @@ function cachedVcsRefsChanges( | 221 | 231 | input: VcsListRefsInput, | 222 | 232 | expectedRevision: number, | 223 | 233 | persistedCacheReadable: boolean, | 224 | | - bypassServerSnapshot: boolean, | 225 | 234 | ) { | 226 | 235 | return followStreamInEnvironment( | 227 | 236 | environmentId, | @@ -233,7 +242,6 @@ function cachedVcsRefsChanges( | 233 | 242 | expectedRevision, | 234 | 243 | registry, | 235 | 244 | persistedCacheReadable, | 236 | | - bypassServerSnapshot, | 237 | 245 | ); | 238 | 246 | }), | 239 | 247 | ), | @@ -250,21 +258,14 @@ export function createVcsEnvironmentAtoms<R, E>( | 250 | 258 | */ | 251 | 259 | const listRefsFamily = Atom.family((key: string) => { | 252 | 260 | const [environmentId, input] = JSON.parse(key) as [EnvironmentId, VcsListRefsInput]; | 253 | | - let builtRevision: number | undefined; | 254 | 261 | return runtime | 255 | 262 | .atom((get) => { | 256 | 263 | const state = get(vcsRefsCacheStateAtom({ environmentId })); | 257 | | - // The server snapshots refs for minutes and only drops them for its own Git | 258 | | - // writes; an invalidation also covers terminal and agent changes, so skip it. | 259 | | - const bypassServerSnapshot = | 260 | | - builtRevision !== undefined && builtRevision !== state.revision; | 261 | | - builtRevision = state.revision; | 262 | 264 | return cachedVcsRefsChanges( | 263 | 265 | environmentId, | 264 | 266 | input, | 265 | 267 | state.revision, | 266 | 268 | state.persistedCacheReadable, | 267 | | - bypassServerSnapshot, | 268 | 269 | ); | 269 | 270 | }) | 270 | 271 | .pipe( | |
|