perf: Cache chat object in upsert_message to avoid redundant DB load#21592
Closed
Classic298 wants to merge 1 commit intoopen-webui:devfrom
Closed
perf: Cache chat object in upsert_message to avoid redundant DB load#21592Classic298 wants to merge 1 commit intoopen-webui:devfrom
Classic298 wants to merge 1 commit intoopen-webui:devfrom
Conversation
👋 Welcome and Thank You for Contributing!We appreciate you taking the time to submit a pull request to Open WebUI!
|
Contributor
|
Addressed in dev. |
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.
upsert_message_to_chat_by_id_and_message_id was calling get_chat_by_id
twice: once at the top to load the chat, and again at line 512 just to
get user_id for the dual-write to chat_message table.
This function fires many times during streaming responses, so each redundant load deserializes the full conversation JSON blob unnecessarily.
upsert_message: Look at that call count: 17 call sites across socket/main.py and middleware.py. This is called during streaming. It's also called when the user's message is first saved, when tool calls happen, when the final response lands. So this one fires many times during a single streaming response, and each was doing 2 full chat loads instead of 1.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.