perf: inline update_chat_title_by_id into single DB context (#23214)

This commit is contained in:
Algorithm5838
2026-04-01 15:06:16 +03:00
committed by GitHub
parent 3f7fc1a75a
commit a28ea36657
+13 -7
View File
@@ -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)