Skip to content

Commit bf81a4a

Browse files
committed
perf: inline update_chat_title_by_id into single DB context
1 parent 661af6c commit bf81a4a

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
@@ -389,15 +389,21 @@ def update_chat_by_id(self, id: str, chat: dict, db: Optional[Session] = None) -
389389
return None
390390

391391
def update_chat_title_by_id(self, id: str, title: str) -> Optional[ChatModel]:
392-
chat = self.get_chat_by_id(id)
393-
if chat is None:
392+
try:
393+
with get_db_context() as db:
394+
chat_item = db.get(Chat, id)
395+
if chat_item is None:
396+
return None
397+
clean_title = self._clean_null_bytes(title)
398+
chat_item.title = clean_title
399+
chat_item.chat = {**(chat_item.chat or {}), 'title': clean_title}
400+
chat_item.updated_at = int(time.time())
401+
db.commit()
402+
db.refresh(chat_item)
403+
return ChatModel.model_validate(chat_item)
404+
except Exception:
394405
return None
395406

396-
chat = chat.chat
397-
chat['title'] = title
398-
399-
return self.update_chat_by_id(id, chat)
400-
401407
def update_chat_tags_by_id(self, id: str, tags: list[str], user) -> Optional[ChatModel]:
402408
with get_db_context() as db:
403409
chat = db.get(Chat, id)

0 commit comments

Comments
 (0)