Skip to content

Commit f4380f8

Browse files
committed
perf: inline update_chat_title_by_id into single DB context
1 parent 377e611 commit f4380f8

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
@@ -389,15 +389,23 @@ 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_data = chat_item.chat or {}
399+
chat_data['title'] = clean_title
400+
chat_item.title = clean_title
401+
chat_item.chat = chat_data
402+
chat_item.updated_at = int(time.time())
403+
db.commit()
404+
db.refresh(chat_item)
405+
return ChatModel.model_validate(chat_item)
406+
except Exception:
394407
return None
395408

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

0 commit comments

Comments
 (0)