Skip to content

Commit c82646c

Browse files
Algorithm5838github-actions[bot]
authored andcommitted
perf: inline update_chat_title_by_id into single DB context
1 parent 2a74011 commit c82646c

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

backend/open_webui/models/chats.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,23 @@ def update_chat_by_id(self, id: str, chat: dict, db: Optional[Session] = None) -
398398
return None
399399

400400
def update_chat_title_by_id(self, id: str, title: str) -> Optional[ChatModel]:
401-
chat = self.get_chat_by_id(id)
402-
if chat is None:
401+
try:
402+
with get_db_context() as db:
403+
chat_item = db.get(Chat, id)
404+
if chat_item is None:
405+
return None
406+
clean_title = self._clean_null_bytes(title)
407+
chat_data = chat_item.chat or {}
408+
chat_data['title'] = clean_title
409+
chat_item.title = clean_title
410+
chat_item.chat = chat_data
411+
chat_item.updated_at = int(time.time())
412+
db.commit()
413+
db.refresh(chat_item)
414+
return ChatModel.model_validate(chat_item)
415+
except Exception:
403416
return None
404417

405-
chat = chat.chat
406-
chat['title'] = title
407-
408-
return self.update_chat_by_id(id, chat)
409-
410418
def update_chat_tags_by_id(self, id: str, tags: list[str], user) -> Optional[ChatModel]:
411419
with get_db_context() as db:
412420
chat = db.get(Chat, id)

0 commit comments

Comments
 (0)