Skip to content

Commit 0650b10

Browse files
Algorithm5838github-actions[bot]
authored andcommitted
perf: inline update_chat_title_by_id into single DB context
1 parent 7eaace2 commit 0650b10

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

backend/open_webui/models/chats.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,21 @@ 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_item.title = clean_title
408+
chat_item.chat = {**(chat_item.chat or {}), 'title': clean_title}
409+
chat_item.updated_at = int(time.time())
410+
db.commit()
411+
db.refresh(chat_item)
412+
return ChatModel.model_validate(chat_item)
413+
except Exception:
403414
return None
404415

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

0 commit comments

Comments
 (0)