fix: race condition in topic auto renaming
This commit is contained in:
parent
464634d051
commit
e5aaec2129
@ -11,6 +11,8 @@ import { useEffect, useState } from 'react'
|
||||
import { useAssistant } from './useAssistant'
|
||||
import { getStoreSetting } from './useSettings'
|
||||
|
||||
const renamingTopics = new Set<string>()
|
||||
|
||||
let _activeTopic: Topic
|
||||
let _setActiveTopic: (topic: Topic) => void
|
||||
|
||||
@ -54,6 +56,13 @@ export async function getTopicById(topicId: string) {
|
||||
}
|
||||
|
||||
export const autoRenameTopic = async (assistant: Assistant, topicId: string) => {
|
||||
if (renamingTopics.has(topicId)) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
renamingTopics.add(topicId)
|
||||
|
||||
const topic = await getTopicById(topicId)
|
||||
const enableTopicNaming = getStoreSetting('enableTopicNaming')
|
||||
|
||||
@ -84,6 +93,9 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) =>
|
||||
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
renamingTopics.delete(topicId)
|
||||
}
|
||||
}
|
||||
|
||||
// Convert class to object with functions since class only has static methods
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user