feat: cache notifications in IndexedDB via storageManager#73
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d61ee5154
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| CategoryID: number | ||
| }>() | ||
|
|
||
| const notificationCacheKey = `notifications:${CategoryID}:${locale.value}` |
There was a problem hiding this comment.
Include user identity in notification cache key
The new cache key only uses CategoryID and locale, so cached notifications are shared across accounts on the same browser profile. On a logout/login switch, restoreNotificationsFromCache() will hydrate another user's messages before any API response arrives, which is a privacy leak and can also leave the list offset (skip) inconsistent for the new account. Add a stable per-user identifier to the key (or clear this store on auth change) to keep notification data isolated.
Useful? React with 👍 / 👎.
| const cached = await storageManager.getObjFromIDB<NotificationMessage[]>(notificationCacheKey) | ||
| if (cached.status !== 'success' || cached.value == null || cached.value.length === 0) return | ||
| items.value = cached.value | ||
| skip.value = cached.value.length |
There was a problem hiding this comment.
Reset offset when refreshing after restoring cached items
Setting skip to cached.value.length causes offset pagination to miss newly arrived notifications. If new messages were inserted at the top since the cache was written, the next /Messages/GetMessages call (which uses Skip: skip.value) skips over those unseen entries, so users can miss fresh notifications indefinitely. After restoring cache, refresh should fetch from the head (or use a cursor/anchor) instead of reusing list length as an offset.
Useful? React with 👍 / 👎.
Motivation
Description
localStorageswithnotificationsCacheand added IndexedDB helpersopenIDB,idbGet, andidbSettosrc/services/storage/index.ts.getObjFromIDBandsetObjToIDBonstorageManagerto read/write structured entries via IndexedDB.src/components/messages/NotificationList.vueto restore cached notifications on startup using the cache keynotifications:${CategoryID}:${locale.value}, merge fetched pages with existing items, deduplicate byID, and persist merged results to IndexedDB.Testing
npm run build(includesvue-tsctype check) and the build completed successfully.Codex Task