From 3d61ee5154b5d03dc92df095de583498c639d6e3 Mon Sep 17 00:00:00 2001 From: gushishang <117088703+gushishang@users.noreply.github.com> Date: Sun, 17 May 2026 23:12:12 +0800 Subject: [PATCH] feat: cache immutable notifications in IndexedDB via storage layer --- src/components/messages/NotificationList.vue | 18 +++++- src/services/storage/index.ts | 58 ++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/components/messages/NotificationList.vue b/src/components/messages/NotificationList.vue index 36bb8c7..32f822a 100644 --- a/src/components/messages/NotificationList.vue +++ b/src/components/messages/NotificationList.vue @@ -87,6 +87,8 @@ const { CategoryID } = defineProps<{ CategoryID: number }>() +const notificationCacheKey = `notifications:${CategoryID}:${locale.value}` + function fillInTemplate(data: string | null, message: Message) { const re = (data ?? '') .replace( @@ -209,7 +211,10 @@ const handleLoad = async (noTemplates = true) => { } }) - items.value = [...items.value, ...defaultItems] + const merged = [...items.value, ...defaultItems] + const deduplicated = Array.from(new Map(merged.map((item) => [item.ID, item])).values()) + items.value = deduplicated + await storageManager.setObjToIDB(notificationCacheKey, items.value) loading.value = false skip.value += 20 } catch (error) { @@ -217,7 +222,16 @@ const handleLoad = async (noTemplates = true) => { } } -handleLoad(false) +async function restoreNotificationsFromCache() { + const cached = await storageManager.getObjFromIDB(notificationCacheKey) + if (cached.status !== 'success' || cached.value == null || cached.value.length === 0) return + items.value = cached.value + skip.value = cached.value.length +} + +restoreNotificationsFromCache().finally(() => { + handleLoad(false) +})