From 3560d2f6305a9ddcdf9e3db54ad283deec94dd22 Mon Sep 17 00:00:00 2001 From: Constantine Date: Fri, 24 Apr 2026 12:34:57 +0300 Subject: [PATCH] perf(chats): drop redundant db.refresh after commit in update_chat_by_id (#24024) The chat table has no computed columns (no DEFAULT, SERIAL/IDENTITY, or TRIGGER that populate server-side values on UPDATE), and every column modified by update_chat_by_id is set explicitly from Python values earlier in the function. db.refresh therefore issues a SELECT that replaces those just-written Python values with the round-tripped database representation of the same values, which is a no-op for functional purposes but pulls the entire chat.chat JSON blob back over the network and through the driver's JSON decoder. On large, active chats where chat.chat can reach tens of megabytes, skipping the refresh measurably reduces latency and eliminates one ~JSON-sized transient allocation per write. --- backend/open_webui/models/chats.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index ba6611a811..bcf6951e49 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -393,7 +393,6 @@ class ChatTable: chat_item.updated_at = int(time.time()) await db.commit() - await db.refresh(chat_item) return ChatModel.model_validate(chat_item) except Exception: