From 32cfb5788a52447d9add2f6c3353db328bc8298b Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Fri, 17 Apr 2026 05:35:58 +0200 Subject: [PATCH] perf(chats): select only meta column in get_chat_tags_by_id_and_user_id (#23798) Avoid loading the full Chat row (including the potentially large `chat` JSON column) just to read tag IDs from `meta.tags`. Issue a narrow SELECT on `Chat.meta` instead, which is much cheaper for chats with large message histories. Co-authored-by: Claude --- backend/open_webui/models/chats.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 7583f9342..be65a92c9 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -1264,8 +1264,10 @@ class ChatTable: self, id: str, user_id: str, db: Optional[AsyncSession] = None ) -> list[TagModel]: async with get_async_db_context(db) as db: - chat = await db.get(Chat, id) - tag_ids = chat.meta.get('tags', []) + stmt = select(Chat.meta).where(Chat.id == id) + result = await db.execute(stmt) + meta = result.scalar_one_or_none() + tag_ids = (meta or {}).get('tags', []) return await Tags.get_tags_by_ids_and_user_id(tag_ids, user_id, db=db) async def get_chat_list_by_user_id_and_tag_name(