From 5f22d21dc7ba965dfd01e26acf09019c2ead39d4 Mon Sep 17 00:00:00 2001 From: murashit Date: Fri, 10 Jul 2026 13:15:34 +0900 Subject: [PATCH] Remove direct query cache access and unused readers --- src/app-server/query/cache.ts | 11 +------- src/app-server/query/keys.ts | 6 ---- src/app-server/query/shared-queries.ts | 4 --- .../threads/catalog/thread-catalog.ts | 3 -- tests/app-server/query-cache.test.ts | 28 ++++++++----------- tests/settings/settings-tab.test.ts | 1 - 6 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/app-server/query/cache.ts b/src/app-server/query/cache.ts index 8993f4f9..be44c5bf 100644 --- a/src/app-server/query/cache.ts +++ b/src/app-server/query/cache.ts @@ -20,7 +20,6 @@ import { activeThreadsQueryKey, appServerMetadataQueryKey, appServerModelsQueryKey, - appServerQueriesFilter, appServerQueryContextIsComplete, archivedThreadsQueryKey, cloneAppServerQueryContext, @@ -52,7 +51,7 @@ type ThreadListKind = "active" | "archived"; type ThreadListUpdater = (threads: readonly Thread[] | null) => readonly Thread[] | null; export class AppServerQueryCache { - readonly client: QueryClient; + private readonly client: QueryClient; private readonly clientRunner: AppServerQueryClientRunner | null; private readonly activeThreadCursors = new Map(); @@ -66,14 +65,6 @@ export class AppServerQueryCache { this.client.clear(); } - clearContext(context: AppServerQueryContext): void { - if (!appServerQueryContextIsComplete(context)) return; - const filter = appServerQueriesFilter(context); - void this.client.cancelQueries(filter); - this.client.removeQueries(filter); - this.activeThreadCursors.delete(this.activeThreadCursorKey(context)); - } - activeThreadsSnapshot(context: AppServerQueryContext): readonly Thread[] | null { return this.threadListSnapshot(context, "active"); } diff --git a/src/app-server/query/keys.ts b/src/app-server/query/keys.ts index b599da4e..885ff072 100644 --- a/src/app-server/query/keys.ts +++ b/src/app-server/query/keys.ts @@ -1,5 +1,3 @@ -import type { QueryKey } from "@tanstack/query-core"; - export interface AppServerQueryContext { codexPath: string; vaultPath: string; @@ -47,10 +45,6 @@ export function appServerModelsQueryKey(context: AppServerQueryContext): AppServ return [...appServerQueryScope(context), "models"]; } -export function appServerQueriesFilter(context: AppServerQueryContext): { queryKey: QueryKey } { - return { queryKey: appServerQueryScope(context) }; -} - function nonEmptyString(value: string): boolean { return value.trim().length > 0; } diff --git a/src/app-server/query/shared-queries.ts b/src/app-server/query/shared-queries.ts index 8834d759..f9476a99 100644 --- a/src/app-server/query/shared-queries.ts +++ b/src/app-server/query/shared-queries.ts @@ -56,10 +56,6 @@ export class AppServerSharedQueries { return this.runForCurrentContext((context) => this.options.cache.loadMoreActiveThreads(context)); } - fetchArchivedThreads(): Promise { - return this.runForCurrentContext((context) => this.options.cache.fetchArchivedThreads(context)); - } - refreshActiveThreads(): Promise { return this.runForCurrentContext((context) => this.options.cache.refreshActiveThreads(context)); } diff --git a/src/features/threads/catalog/thread-catalog.ts b/src/features/threads/catalog/thread-catalog.ts index 2c572d3b..d9e3e782 100644 --- a/src/features/threads/catalog/thread-catalog.ts +++ b/src/features/threads/catalog/thread-catalog.ts @@ -11,7 +11,6 @@ interface ThreadCatalogStore { fetchAllActiveThreads(): Promise; hasMoreActiveThreads(): boolean; loadMoreActiveThreads(): Promise; - fetchArchivedThreads(): Promise; refreshActiveThreads(): Promise; refreshArchivedThreads(): Promise; observeActiveThreadsResult(observer: ThreadListObserver, options?: { emitCurrent?: boolean }): () => void; @@ -73,7 +72,6 @@ export interface ThreadCatalogPaginatedActiveReader extends ThreadCatalogActiveR export interface ThreadCatalogArchivedReader { archivedSnapshot(): readonly Thread[] | null; - loadArchived(): Promise; refreshArchived(): Promise; observeArchived(observer: ThreadListObserver, options?: { emitCurrent?: boolean }): () => void; } @@ -109,7 +107,6 @@ export function createThreadCatalog(options: ThreadCatalogOptions): ThreadCatalo }); }, observeOptions), archivedSnapshot: () => threadListProjection(store.archivedThreadsSnapshot(), currentFacts().archived), - loadArchived: () => loadThreadList(store.fetchArchivedThreads(), currentFacts().archived), refreshArchived: () => loadThreadList(store.refreshArchivedThreads(), currentFacts().archived), observeArchived: (observer, observeOptions) => store.observeArchivedThreadsResult((result) => { diff --git a/tests/app-server/query-cache.test.ts b/tests/app-server/query-cache.test.ts index 81dbda88..3b3b3b72 100644 --- a/tests/app-server/query-cache.test.ts +++ b/tests/app-server/query-cache.test.ts @@ -17,10 +17,19 @@ import { import type { SharedServerMetadata } from "../../src/domain/server/metadata"; describe("AppServerQueryCache", () => { - it("allows inactive query contexts to be garbage-collected", () => { - const cache = new AppServerQueryCache(); + it("garbage-collects inactive query contexts", async () => { + vi.useFakeTimers(); + try { + const cache = new AppServerQueryCache(); + const context = cacheContext(); + cache.setActiveThreads(context, [thread("temporary")]); - expect(cache.client.getDefaultOptions().queries?.gcTime).toBe(300_000); + await vi.advanceTimersByTimeAsync(300_001); + + expect(cache.activeThreadsSnapshot(context)).toBeNull(); + } finally { + vi.useRealTimers(); + } }); it("preserves successful metadata resource values when probes fail", () => { @@ -398,19 +407,6 @@ describe("AppServerQueryCache", () => { expect(cache.appServerMetadataSnapshot(context)).toEqual(refreshed); }); - it("clears thread list snapshots by context", () => { - const cache = new AppServerQueryCache(); - const context = cacheContext(); - - cache.setActiveThreads(context, [thread("thread")]); - - expect(cache.activeThreadsSnapshot(context)).toEqual([thread("thread")]); - - cache.clearContext(context); - - expect(cache.activeThreadsSnapshot(context)).toBeNull(); - }); - it("does not merge local thread list updates into in-flight app-server snapshots", async () => { const context = cacheContext(); const refresh = deferred[]>(); diff --git a/tests/settings/settings-tab.test.ts b/tests/settings/settings-tab.test.ts index bcddfac9..cdab4fa8 100644 --- a/tests/settings/settings-tab.test.ts +++ b/tests/settings/settings-tab.test.ts @@ -1107,7 +1107,6 @@ function settingsTabHost( }; const threadCatalog = { archivedSnapshot: vi.fn(() => options.archivedSnapshot ?? null), - loadArchived: vi.fn().mockResolvedValue(options.archivedThreads ?? defaultArchivedThreads), refreshArchived: options.refreshArchived ?? vi.fn().mockResolvedValue(options.archivedThreads ?? defaultArchivedThreads), observeArchived: options.observeArchived ?? vi.fn(() => () => undefined), apply: options.applyThreadCatalogEvent ?? vi.fn(),