fix: protect live session sync caches

This commit is contained in:
Bohdan Triapitsyn
2026-05-07 12:30:30 +03:00
parent 07edd6e9b9
commit ff830d3812
5 changed files with 89 additions and 5 deletions
+4 -2
View File
@@ -10,7 +10,7 @@ import {
type OptimisticItem,
} from "./optimistic"
import { useDirectoryStore, useSyncSDK, useSyncDirectory, useChildStoreManager } from "./sync-context"
import { dropSessionCaches } from "./session-cache"
import { dropSessionCaches, getProtectedSessionCacheIds } from "./session-cache"
import { stripMessageDiffSnapshots } from "./sanitize"
import {
shouldSkipSessionPrefetch,
@@ -135,14 +135,16 @@ export function useSync() {
const touch = useCallback(
(sessionID: string) => {
const s = seenFor()
const protectedIds = getProtectedSessionCacheIds(store.getState())
const stale = pickSessionCacheEvictions({
seen: s,
keep: sessionID,
limit: SESSION_CACHE_LIMIT,
preserve: protectedIds,
})
evict(directory, stale)
},
[directory, seenFor, evict],
[directory, seenFor, evict, store],
)
// Optimistic operations