mirror of
https://github.com/morgan9e/chatgpt-web
synced 2026-04-14 00:14:04 +09:00
Use cache flush timer per chatId
This commit is contained in:
@@ -235,18 +235,19 @@
|
||||
}, 10)
|
||||
}
|
||||
|
||||
let setMessagesTimer: any
|
||||
const setMessagesTimers: any = {}
|
||||
export const setMessages = (chatId: number, messages: Message[]) => {
|
||||
if (get(currentChatId) === chatId) {
|
||||
// update current message cache right away
|
||||
currentChatMessages.set(messages)
|
||||
clearTimeout(setMessagesTimer)
|
||||
clearTimeout(setMessagesTimers[chatId])
|
||||
// delay expensive all chats update for a bit
|
||||
setMessagesTimer = setTimeout(() => {
|
||||
setMessagesTimers[chatId] = setTimeout(() => {
|
||||
getChat(chatId).messages = messages
|
||||
saveChatStore()
|
||||
}, 200)
|
||||
} else {
|
||||
clearTimeout(setMessagesTimers[chatId])
|
||||
getChat(chatId).messages = messages
|
||||
saveChatStore()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user