mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 08:25:01 -06:00
perf: inline update_chat_title_by_id into single DB context (#23214)
This commit is contained in:
@@ -415,15 +415,21 @@ class ChatTable:
|
||||
return False
|
||||
|
||||
def update_chat_title_by_id(self, id: str, title: str) -> Optional[ChatModel]:
|
||||
chat = self.get_chat_by_id(id)
|
||||
if chat is None:
|
||||
try:
|
||||
with get_db_context() as db:
|
||||
chat_item = db.get(Chat, id)
|
||||
if chat_item is None:
|
||||
return None
|
||||
clean_title = self._clean_null_bytes(title)
|
||||
chat_item.title = clean_title
|
||||
chat_item.chat = {**(chat_item.chat or {}), 'title': clean_title}
|
||||
chat_item.updated_at = int(time.time())
|
||||
db.commit()
|
||||
db.refresh(chat_item)
|
||||
return ChatModel.model_validate(chat_item)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
chat = chat.chat
|
||||
chat['title'] = title
|
||||
|
||||
return self.update_chat_by_id(id, chat)
|
||||
|
||||
def update_chat_tags_by_id(self, id: str, tags: list[str], user) -> Optional[ChatModel]:
|
||||
with get_db_context() as db:
|
||||
chat = db.get(Chat, id)
|
||||
|
||||
Reference in New Issue
Block a user