fix: optimize chat ID retrieval to prevent multiple concurrent requests - #6581
Merged
Conversation
Contributor
Author
|
Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information |
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce duplicate “open chat” (openChatId) requests by deduplicating chat-id retrieval when multiple file uploads start concurrently in the AI chat input component.
Changes:
- Add an in-flight
chatIdPromisecache to reuse the sameopenChatId()request across concurrentuploadFilecalls. - Reset the cached promise when the request completes (success or failure) via
.finally().
Suppressed comments (1)
ui/src/components/ai-chat/component/chat-input-operate/index.vue:558
- This promise dedupe only applies within
uploadFilein this component. Other call sites can still trigger concurrentopenChatId()requests (e.g. chat send path inui/src/components/ai-chat/index.vue), so multiple/openrequests and a last-writer-wins chat-id race are still possible. Consider moving the memoization into theopenChatIdimplementation (parent) so all call sites share the same in-flight promise.
if (!chatIdPromise) {
chatIdPromise = props.openChatId().finally(() => {
chatIdPromise = null
})
}
chatId_context.value = await chatIdPromise
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
552
to
559
| if (!chatId_context.value) { | ||
| chatId_context.value = await props.openChatId() | ||
| if (!chatIdPromise) { | ||
| chatIdPromise = props.openChatId().finally(() => { | ||
| chatIdPromise = null | ||
| }) | ||
| } | ||
| chatId_context.value = await chatIdPromise | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: optimize chat ID retrieval to prevent multiple concurrent requests