From 945f1b365133b0d74c5d572cddabb620b02e76c2 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Thu, 26 Jun 2025 10:18:39 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=82=AE=E7=AE=B1=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/EmailActions.js | 6 +++--- src/stores/EmailSlice.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/actions/EmailActions.js b/src/actions/EmailActions.js index 4885a54..42cdcf4 100644 --- a/src/actions/EmailActions.js +++ b/src/actions/EmailActions.js @@ -208,7 +208,7 @@ export const getMailboxCountAction = async (params = { opi_sn: '' }, update = tr const ret = errcode !== 0 ? { [`${params.opi_sn}`]: {} } : { [`${params.opi_sn}`]: result } // 更新数量 if (update !== false) { - const readCacheDir = await readIndexDB(Number(params.opi_sn), 'dirs', 'mailbox'); + const readCacheDir = (await readIndexDB(Number(params.opi_sn), 'dirs', 'mailbox')) || {}; const mailboxDir = isEmpty(readCacheDir) ? [] : readCacheDir.tree.filter(node => node?._raw?.IsTrue === 1); const _MapDir = new Map(mailboxDir.map((obj) => [obj.key, obj])) Object.keys(result).map(dirKey => { @@ -220,7 +220,7 @@ export const getMailboxCountAction = async (params = { opi_sn: '' }, update = tr _MapRoot.set(row.key, row) }) const _newRoot = Array.from(_MapRoot.values()) - writeIndexDB([{ key: Number(params.opi_sn), tree: _newRoot }], 'dirs', 'mailbox') + writeIndexDB([{ ...readCacheDir, key: Number(params.opi_sn), tree: _newRoot }], 'dirs', 'mailbox') notifyMailboxUpdate({ type: 'dirs', key: Number(params.opi_sn) }) } @@ -338,7 +338,7 @@ export const getRootMailboxDirAction = async ({ opi_sn = 0, userIdStr = '' } = { const mailBoxCount = await Promise.all(userIdStr.split(',').map(_opi => getMailboxCountAction({ opi_sn: _opi }, false))); const mailboxDirCountByOPI = mailBoxCount.reduce((a, c) => ({ ...a, ...c, }), {}) const mailboxDirByOPI = mailboxDir.reduce((a, c) => ({ ...a, ...(Object.keys(c).reduce((a, opi) => ({...a, [opi]: c[`${opi}`].map((dir) => ({ ...dir, count: mailboxDirCountByOPI[opi][`${dir.key}`] })) }), {} )) }), {}) - const rootTree = Object.keys(stickyTree).map((opi) => ({ key: Number(opi), tree: [...stickyTree[opi], ...(mailboxDirByOPI?.[opi] || [])] })) + const rootTree = Object.keys(stickyTree).map((opi) => ({ key: Number(opi), tree: [...stickyTree[opi], ...(mailboxDirByOPI?.[opi] || [])], treeTimestamp: Date.now() })) writeIndexDB(rootTree, 'dirs', 'mailbox') const _mapped = groupBy(rootTree, 'key') return _mapped[opi_sn]?.[0]?.tree || [] diff --git a/src/stores/EmailSlice.js b/src/stores/EmailSlice.js index 30276b6..4974e81 100644 --- a/src/stores/EmailSlice.js +++ b/src/stores/EmailSlice.js @@ -124,7 +124,7 @@ const emailSlice = (set, get) => ({ let isNeedRefresh = refreshNow if (!isEmpty(readCache)) { setMailboxNestedDirsActive(readCache?.tree || []) - isNeedRefresh = refreshNow || Date.now() - readCache.timestamp > 1 * 60 * 60 * 1000 + isNeedRefresh = refreshNow || Date.now() - readCache.treeTimestamp > 1 * 60 * 60 * 1000 // isNeedRefresh = true; // test: 0 } if (isEmpty(readCache) || isNeedRefresh) { @@ -141,7 +141,7 @@ const emailSlice = (set, get) => ({ // 更新数量 updateMailboxCount: async ({ opi_sn }) => { - const { setMailboxNestedDirsActive } = get() + // const { setMailboxNestedDirsActive } = get() await getMailboxCountAction({ opi_sn }) // const readCache = await readIndexDB(Number(opi_sn), 'dirs', 'mailbox') // if (!isEmpty(readCache)) { @@ -150,7 +150,7 @@ const emailSlice = (set, get) => ({ }, async initMailbox({ opi_sn, dei_sn, userIdStr }) { - olog('initMailbox ---- ') + olog('Initialize Mailbox ---- ') const { currentMailboxOPI, setCurrentMailboxOPI, setCurrentMailboxDEI, getOPIEmailDir, setMailboxNestedDirsActive, } = get() createIndexedDBStore(['dirs', 'maillist', 'listrow', 'mailinfo', 'draft'], 'mailbox') setCurrentMailboxOPI(opi_sn)