fix(mobile-history): drop history cache writes that outlive the auth scope

This commit is contained in:
Yun Chan 2026-09-28 00:54:01 +09:00
parent 2576f4af7b
commit e243e5282c
5 changed files with 431 additions and 32 deletions

View file

@ -61,7 +61,8 @@ import type { NotificationNavigationTarget } from './src/features/notifications/
import { loadPendingInviteToken } from './src/features/teams/pending-invite'
import { listTeams } from './src/features/teams/team-service'
import { listHistoryPage } from './src/features/history/history-service'
import { saveHistoryCache } from './src/features/history/history-cache'
import { createHistoryCacheScope } from './src/features/history/history-cache-writer'
import { synchronizeAfterMissedNotifications } from './src/features/notifications/missed-notification-sync'
import { useRecordingProcessingQueue } from './src/features/recording/use-recording-processing-queue'
import {
getPendingIncomingMediaId,
@ -246,22 +247,22 @@ function RootNavigator(): React.ReactElement {
void routeIncomingMedia()
}, [routeIncomingMedia])
// Invalidated whenever the signed-in user changes (including the null that
// the logout privacy purge publishes) so an in-flight full sync cannot write
// the previous account's history cache back after the purge.
const [historyCacheScope] = useState(createHistoryCacheScope)
useEffect(() => () => historyCacheScope.invalidate(), [historyCacheScope, user?.id])
const synchronizeMissedNotifications = useCallback(async (): Promise<boolean> => {
const userId = user?.id
if (!userId) return false
try {
const [history] = await Promise.all([
listHistoryPage({ userId, filter: 'all', pageSize: 50 }),
listTeams(userId),
fetchEntitlementSnapshot(userId),
])
await saveHistoryCache(userId, history.entries)
await entitlement.refresh()
return true
} catch {
return false
}
}, [entitlement, user?.id])
return synchronizeAfterMissedNotifications(userId, historyCacheScope.capture(), {
listRecentHistory: (id) => listHistoryPage({ userId: id, filter: 'all', pageSize: 50 }),
listTeams,
fetchEntitlement: fetchEntitlementSnapshot,
refreshEntitlement: () => entitlement.refresh(),
})
}, [entitlement, historyCacheScope, user?.id])
useNotificationRuntime({
navigate: navigateFromNotification,