mirror of
https://github.com/open-webui/open-webui.git
synced 2026-06-04 07:47:12 -05:00
[PR #21592] [CLOSED] perf: Cache chat object in upsert_message to avoid redundant DB load #97192
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21592
Author: @Classic298
Created: 2/19/2026
Status: ❌ Closed
Base:
dev← Head:perf-upsert-chat📝 Commits (1)
83da507Cache chat object in upsert_message to avoid redundant DB load📊 Changes
1 file changed (+6 additions, -4 deletions)
View changed files
📝
backend/open_webui/models/chats.py(+6 -4)📄 Description
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.