fix(search): "Clear cached index" was undone immediately by the active search re-persisting its in-memory rows (#184 O4)
CI / Build & Quality Checks (push) Successful in 1m50s
CI / Docker image build & smoke test (push) Skipped
CI / Secret scan (gitleaks) (push) Successful in 33s
CI / Trigger Desktop Build (push) Successful in 7s
CI / Playwright smoke (e2e) (push) Successful in 2m2s

Clearing bumps cacheVersion so the search re-runs, and the re-run wrote
the scanned rows straight back to IndexedDB, so the index was never empty
while the button was visible. Skip persistence for that one re-run.
Verified: IDB stores go to 0/0 after Clear; logout still deletes the DB.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
2026-09-18 18:34:55 -04:00
co-authored by Claude Opus 5
parent 22371f8156
commit 14b6849f6e
2 changed files with 19 additions and 2 deletions
@@ -18,6 +18,12 @@ export type LocalSearchParams = {
/** Optional date-range filter (ms). Applied to both memory and cached rows. */
fromTs?: number;
toTs?: number;
/**
* Set false to run the scan without writing it back to IndexedDB — used
* right after "Clear cached index" so the clear is not undone by the
* re-run of the active search (Gitea #184 O4).
*/
persist?: boolean;
};
export type LocalSearchResult = {
@@ -149,6 +155,7 @@ export const useLocalMessageSearch = () => {
senders,
fromTs,
toTs,
persist = true,
}: LocalSearchParams): Promise<LocalSearchResult> => {
const trimmedTerm = term.trim();
const senderSet = senders && senders.length > 0 ? new Set(senders) : null;
@@ -302,7 +309,7 @@ export const useLocalMessageSearch = () => {
// Fire-and-forget persist of freshly scanned rows + coverage.
// saveRoomIndex swallows all errors internally, so a floating promise
// here can never reject.
if (cacheEnabled && rowsToPersist.length > 0) {
if (cacheEnabled && persist && rowsToPersist.length > 0) {
saveRoomIndex(roomId, rowsToPersist);
}
}