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.
This commit is contained in:
Jinwoo-H
2026-09-10 23:29:14 -04:00
parent 7321c9104e
commit b0a8295bb3
@@ -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 []