History

fix(server): preserve active VCS cache entries

Ben Davis committed 4 months ago

Commit 4a4df051 parent f891d522 files · +11 −2Browse files

Unified · Split

2 files
  1. apps/server/src/provider/Layers/EventNdjsonLogger.ts +1 −1
  2. apps/server/src/vcs/VcsStatusBroadcaster.ts +10 −1
apps/server/src/provider/Layers/EventNdjsonLogger.ts+1−1
@@ -296,7 +296,7 @@ function enforceRetention(input: { · 295 unmodified lines
296 (left, right) => left.mtimeMs - right.mtimeMs || left.filePath.localeCompare(right.filePath),296 (left, right) => left.mtimeMs - right.mtimeMs || left.filePath.localeCompare(right.filePath),
297 )) {297 )) {
298 if (totalBytes <= input.maxTotalBytes) break;298 if (totalBytes <= input.maxTotalBytes) break;
299 remove(file);299 if (!remove(file)) break;
300 }300 }
301 301
302 return { failures, removedCount, totalBytes };302 return { failures, removedCount, totalBytes };
apps/server/src/vcs/VcsStatusBroadcaster.ts+10−1
@@ -190,6 +190,7 @@ export const make = Effect.gen(function* () { · 189 unmodified lines
190 Scope.close(scope, Exit.void),190 Scope.close(scope, Exit.void),
191 );191 );
192 const statusCache = new Map<string, CachedVcsStatus>();192 const statusCache = new Map<string, CachedVcsStatus>();
193 const activeRemotePollerCwds = new Set<string>();
193 const pollersRef = yield* SynchronizedRef.make(new Map<string, ActiveRemotePoller>());194 const pollersRef = yield* SynchronizedRef.make(new Map<string, ActiveRemotePoller>());
194 195
195 const setCachedStatus = (cwd: string, status: CachedVcsStatus) => {196 const setCachedStatus = (cwd: string, status: CachedVcsStatus) => {
@@ -197,7 +198,13 @@ export const make = Effect.gen(function* () { · 1 unmodified line
197 statusCache.set(cwd, status);198 statusCache.set(cwd, status);
198 199
199 while (statusCache.size > VCS_STATUS_CACHE_CAPACITY) {200 while (statusCache.size > VCS_STATUS_CACHE_CAPACITY) {
200 const oldestCwd = statusCache.keys().next().value;201 let oldestCwd: string | undefined;
202 for (const cachedCwd of statusCache.keys()) {
203 if (!activeRemotePollerCwds.has(cachedCwd)) {
204 oldestCwd = cachedCwd;
205 break;
206 }
207 }
201 if (oldestCwd === undefined) {208 if (oldestCwd === undefined) {
202 break;209 break;
203 }210 }
@@ -489,6 +496,7 @@ export const make = Effect.gen(function* () { · 285 unmodified lines
489 return makeRemoteRefreshLoop(cwd, automaticRemoteRefreshInterval, refreshImmediately).pipe(496 return makeRemoteRefreshLoop(cwd, automaticRemoteRefreshInterval, refreshImmediately).pipe(
490 Effect.forkIn(broadcasterScope),497 Effect.forkIn(broadcasterScope),
491 Effect.map((fiber) => {498 Effect.map((fiber) => {
499 activeRemotePollerCwds.add(cwd);
492 const nextPollers = new Map(activePollers);500 const nextPollers = new Map(activePollers);
493 nextPollers.set(cwd, {501 nextPollers.set(cwd, {
494 fiber,502 fiber,
@@ -531,6 +539,7 @@ export const make = Effect.gen(function* () { · 36 unmodified lines
531 }539 }
532 540
533 return Effect.sync(() => {541 return Effect.sync(() => {
542 activeRemotePollerCwds.delete(cwd);
534 statusCache.delete(cwd);543 statusCache.delete(cwd);
535 return [undefined, activePollers] as const;544 return [undefined, activePollers] as const;
536 });545 });