mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 02:48:13 -05:00
[PR #21596] [MERGED] perf: eliminate 2 redundant full chat deserialization on every message send #41786
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/21596
Author: @Classic298
Created: 2/19/2026
Status: ✅ Merged
Merged: 2/21/2026
Merged by: @tjbck
Base:
dev← Head:perf-chat-loading📝 Commits (2)
2dde12bperf: eliminate 2 redundant full chat deserialization on every message send (#162)abe92a0Address maintainer feedback: rename method and inline call (#166)📊 Changes
3 files changed (+42 additions, -6 deletions)
View changed files
📝
backend/open_webui/main.py(+3 -3)📝
backend/open_webui/models/chats.py(+35 -0)📝
backend/open_webui/utils/middleware.py(+4 -3)📄 Description
Problem:
Every message send triggered get_chat_by_id_and_user_id which loads the entire Chat row - including the potentially massive JSON blob containing the full conversation history - even when the caller only needed a simple yes/no ownership check or a single column value.
Two call sites in the message-send hot path were doing this:
if chat is None. The JSON blob was immediately discarded - only the existence of the row mattered.chat.folder_id- a plain column on the chat table that requires zero JSON parsing.Fix:
chat_exists_by_id_and_user_id(): uses SQL EXISTS subquery whichreturns a boolean without loading any row data. The database can satisfy
this from the primary key index alone.
get_chat_folder_id(): queries only thefolder_idcolumn viadb.query(Chat.folder_id), which tells SQLAlchemy to SELECT only thatsingle column instead of the entire row.
Both new methods preserve the same error handling semantics (return False/None on exception) and user_id filtering (ownership check) as the original get_chat_by_id_and_user_id.
Impact:
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.