From b0a8295bb38d6c06a29fe9dc6ec027feb87cd104 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Thu, 10 Sep 2026 14:59:12 -0400 Subject: [PATCH] refactor(ai-vault-search): let indexedSources walk the table it is asked for The per-path arm existed for `invalidate()`, which had to resolve a path the index might never have held. Only the sweep reads this now, and it reads all of it. --- .../ai-vault-search/session-search-store.ts | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/ai-vault-search/session-search-store.ts b/src/main/ai-vault-search/session-search-store.ts index 4a0a8fab67e..5509b1465fb 100644 --- a/src/main/ai-vault-search/session-search-store.ts +++ b/src/main/ai-vault-search/session-search-store.ts @@ -231,19 +231,18 @@ export class SessionSearchStore { } /** - * What this index believes it holds, for a scheduler that has to notice a - * source that vanished while nothing was running. `paths` narrows it to a - * lookup; omitting it walks the whole table, which only a full sweep does. + * Every source this index believes it holds, for the sweep that has to notice + * one that vanished while nothing was running. A whole-table walk, which is + * why only a sweep asks. */ - indexedSources(paths?: readonly string[]): SessionSearchIndexedSource[] { - const sql = `SELECT f.path AS path, s.agent AS agent, s.codex_home AS codexHome - FROM files f LEFT JOIN sessions s ON s.id = f.session_row_id` + indexedSources(): SessionSearchIndexedSource[] { try { - if (!paths) { - return this.db.prepare(sql).all() as SessionSearchIndexedSource[] - } - const one = this.db.prepare(`${sql} WHERE f.path = ?`) - return paths.flatMap((path) => one.all(path) as SessionSearchIndexedSource[]) + return this.db + .prepare( + `SELECT f.path AS path, s.agent AS agent, s.codex_home AS codexHome + FROM files f LEFT JOIN sessions s ON s.id = f.session_row_id` + ) + .all() as SessionSearchIndexedSource[] } catch (error) { this.onError(error) return []