Query title column directly in get_chat_title_by_id instead of loading full chat (#157) (#21590)

Previously loaded the entire ChatModel (including the full conversation JSON
blob) just to extract the title string. Now queries only the Chat.title
column directly, which is already a top-level DB column.
This commit is contained in:
Classic298
2026-02-19 23:41:46 +01:00
committed by GitHub
parent 6d67ac371d
commit 3db6d49e57

View File

@@ -456,11 +456,11 @@ class ChatTable:
return ChatModel.model_validate(chat)
def get_chat_title_by_id(self, id: str) -> Optional[str]:
chat = self.get_chat_by_id(id)
if chat is None:
return None
return chat.chat.get("title", "New Chat")
with get_db_context() as db:
result = db.query(Chat.title).filter_by(id=id).first()
if result is None:
return None
return result[0] or "New Chat"
def get_messages_map_by_chat_id(self, id: str) -> Optional[dict]:
chat = self.get_chat_by_id(id)