mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-17 11:37:06 +08:00
feat: 修改缓存加载逻辑
This commit is contained in:
@@ -263,7 +263,6 @@ function App(): React.ReactElement {
|
||||
const messageHistoryRef = React.useRef<Message[]>([])
|
||||
const messagesRef = React.useRef<Message[]>([])
|
||||
const messagePrefetchRef = React.useRef<Promise<void> | null>(null)
|
||||
const pendingLiveRefreshMd5Ref = React.useRef('')
|
||||
messagesRef.current = messages
|
||||
React.useEffect(() => {
|
||||
if (!reportNotice) return
|
||||
@@ -923,17 +922,13 @@ function App(): React.ReactElement {
|
||||
storeGroupMemberMeta(contact, cachedPage.groupSnapshot)
|
||||
}
|
||||
messageHistoryRef.current = cachedMsgs
|
||||
pendingLiveRefreshMd5Ref.current = cachedPage.hit ? '' : contact.md5
|
||||
setMessages(
|
||||
applyGroupMemberMeta(
|
||||
contact,
|
||||
mergeSyntheticMessages(contact, cachedMsgs.slice(-INITIAL_MESSAGE_COUNT))
|
||||
)
|
||||
)
|
||||
const needsLivePage =
|
||||
forceLive ||
|
||||
(isDatabaseConnected &&
|
||||
(!cachedPage.hit || cachedMsgs.length < MESSAGE_PREFETCH_COUNT))
|
||||
const needsLivePage = forceLive || isDatabaseConnected
|
||||
if (!needsLivePage) {
|
||||
setIsMessagesLoading(false)
|
||||
if (contact.type === 'group' && cachedMsgs.length > 0 && !cachedPage.groupSnapshot) {
|
||||
@@ -959,7 +954,6 @@ function App(): React.ReactElement {
|
||||
})
|
||||
if (selectedContactMd5Ref.current !== contact.md5) return
|
||||
messageHistoryRef.current = msgs
|
||||
pendingLiveRefreshMd5Ref.current = ''
|
||||
const visibleMessages = applyGroupMemberMeta(
|
||||
contact,
|
||||
mergeSyntheticMessages(contact, msgs.slice(-INITIAL_MESSAGE_COUNT))
|
||||
@@ -992,10 +986,6 @@ function App(): React.ReactElement {
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isDatabaseConnected || !selectedContact) return
|
||||
const needsPendingRefresh = pendingLiveRefreshMd5Ref.current === selectedContact.md5
|
||||
if (messages.length > 0 && !needsPendingRefresh) return
|
||||
// The first live page uses async native cursors, so a cache miss can be filled
|
||||
// without blocking the Electron main thread.
|
||||
void handleSelectContact(selectedContact)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isDatabaseConnected])
|
||||
|
||||
Reference in New Issue
Block a user