mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 18:50:56 +08:00
feat: throttle updateTranslationBlock dispatch for improved performance (#6442)
- Introduced throttling to the updateTranslationBlock dispatch function to limit the frequency of updates, enhancing performance during message operations. - Utilized lodash's throttle function to ensure efficient handling of accumulated text updates.
This commit is contained in:
parent
a47c8d4b7d
commit
bf8f49f87e
@ -23,6 +23,7 @@ import type { Assistant, Model, Topic } from '@renderer/types'
|
||||
import type { Message, MessageBlock } from '@renderer/types/newMessage'
|
||||
import { MessageBlockStatus, MessageBlockType } from '@renderer/types/newMessage'
|
||||
import { abortCompletion } from '@renderer/utils/abortController'
|
||||
import { throttle } from 'lodash'
|
||||
import { useCallback } from 'react'
|
||||
|
||||
const selectMessagesState = (state: RootState) => state.messages
|
||||
@ -243,9 +244,13 @@ export function useMessageOperations(topic: Topic) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (accumulatedText: string, isComplete: boolean = false) => {
|
||||
dispatch(updateTranslationBlockThunk(blockId!, accumulatedText, isComplete))
|
||||
}
|
||||
return throttle(
|
||||
(accumulatedText: string, isComplete: boolean = false) => {
|
||||
dispatch(updateTranslationBlockThunk(blockId!, accumulatedText, isComplete))
|
||||
},
|
||||
200,
|
||||
{ leading: true, trailing: true }
|
||||
)
|
||||
},
|
||||
[dispatch, topic.id]
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user