Keep candidate consumption in its storage module

Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
This commit is contained in:
Brennan Benson
2026-11-13 17:13:00 -08:00
co-authored by Jinjing
parent 020256969e
commit 8c72646a97
2 changed files with 19 additions and 9 deletions
@@ -4,6 +4,20 @@ import type { SessionSearchCandidateRow } from './session-search-catalog-candida
import { boundedSessionSearchPage } from './session-search-catalog-pages'
import { sessionSearchStoredCandidate } from './session-search-candidate-facts'
export function consumeSessionSearchCandidatePage(
db: SyncDatabase,
receipts: { key: string; revision: number }[]
): number {
if (!receipts.length) {
return 0
}
const result = db
.prepare(`UPDATE temp.search_candidates SET changed=0
WHERE changed=1 AND (key,revision) IN (SELECT json_extract(value,'$[0]'),json_extract(value,'$[1]') FROM json_each(?))`)
.run(JSON.stringify(receipts.map((row) => [row.key, row.revision])))
return Number(result.changes)
}
export function readSessionSearchCandidateRows(
db: SyncDatabase,
where: string,
@@ -7,7 +7,10 @@ import {
sessionSearchCandidateAdmission,
sessionSearchPathAdmission
} from './session-search-candidate-admission'
import { readSessionSearchCandidateRows } from './session-search-candidate-rows'
import {
readSessionSearchCandidateRows,
consumeSessionSearchCandidatePage
} from './session-search-candidate-rows'
import { boundedSessionSearchPage } from './session-search-catalog-pages'
import { putSessionSearchCandidate } from './session-search-candidate-entry'
import {
@@ -254,14 +257,7 @@ export class SessionSearchCatalogCandidates {
return { rows, references }
}
consumedPage(receipts: { key: string; revision: number }[]): void {
if (!receipts.length) {
return
}
const result = this.db
.prepare(`UPDATE temp.search_candidates SET changed=0
WHERE changed=1 AND (key,revision) IN (SELECT json_extract(value,'$[0]'),json_extract(value,'$[1]') FROM json_each(?))`)
.run(JSON.stringify(receipts.map((row) => [row.key, row.revision])))
this.pending -= Number(result.changes)
this.pending -= consumeSessionSearchCandidatePage(this.db, receipts)
}
rowChanged(path: string): void {
this.publications.rowChanged(path)