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
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:
@@ -246,8 +246,15 @@ export function MessageSearch({
|
||||
const [cacheVersion, setCacheVersion] = useState(0);
|
||||
const handleCacheLoaded = useCallback(() => setCacheVersion((v) => v + 1), []);
|
||||
// Explicit wipe of the persistent on-disk index, then re-run the merge.
|
||||
// After a clear, the active search re-runs (cacheVersion) and would persist
|
||||
// the in-memory rows straight back — skip that one write so "Clear cached
|
||||
// index" actually leaves the disk empty until the next new search.
|
||||
const skipPersistOnceRef = useRef(false);
|
||||
const handleClearSearchCache = useCallback(() => {
|
||||
clearSearchCache().then(() => setCacheVersion((v) => v + 1));
|
||||
clearSearchCache().then(() => {
|
||||
skipPersistOnceRef.current = true;
|
||||
setCacheVersion((v) => v + 1);
|
||||
});
|
||||
}, []);
|
||||
|
||||
// The rooms actually in scope for this search (mirrors server-side logic)
|
||||
@@ -277,12 +284,15 @@ export function MessageSearch({
|
||||
return undefined;
|
||||
}
|
||||
let cancelled = false;
|
||||
const persist = !skipPersistOnceRef.current;
|
||||
skipPersistOnceRef.current = false;
|
||||
searchLocalMessages({
|
||||
term: msgSearchParams.term ?? '',
|
||||
roomIds: localSearchRooms,
|
||||
senders: msgSearchParams.senders,
|
||||
fromTs: msgSearchParams.fromTs,
|
||||
toTs: msgSearchParams.toTs,
|
||||
persist,
|
||||
}).then((result) => {
|
||||
if (!cancelled) setLocalResult(result);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user