Skip to content

Commit a28ea36

Browse files
perf: inline update_chat_title_by_id into single DB context (open-webui#23214)
1 parent 3f7fc1a commit a28ea36

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
@@ -415,15 +415,21 @@ def update_chat_last_read_at_by_id(self, id: str, user_id: str, db: Optional[Ses
415415
return False
416416

417417
def update_chat_title_by_id(self, id: str, title: str) -> Optional[ChatModel]:
418-
chat = self.get_chat_by_id(id)
419-
if chat is None:
418+
try:
419+
with get_db_context() as db:
420+
chat_item = db.get(Chat, id)
421+
if chat_item is None:
422+
return None
423+
clean_title = self._clean_null_bytes(title)
424+
chat_item.title = clean_title
425+
chat_item.chat = {**(chat_item.chat or {}), 'title': clean_title}
426+
chat_item.updated_at = int(time.time())
427+
db.commit()
428+
db.refresh(chat_item)
429+
return ChatModel.model_validate(chat_item)
430+
except Exception:
420431
return None
421432

422-
chat = chat.chat
423-
chat['title'] = title
424-
425-
return self.update_chat_by_id(id, chat)
426-
427433
def update_chat_tags_by_id(self, id: str, tags: list[str], user) -> Optional[ChatModel]:
428434
with get_db_context() as db:
429435
chat = db.get(Chat, id)

0 commit comments

Comments
 (0)