perf(chats): select only meta column in get_chat_tags_by_id_and_user_id (#23798)
Avoid loading the full Chat row (including the potentially large `chat` JSON column) just to read tag IDs from `meta.tags`. Issue a narrow SELECT on `Chat.meta` instead, which is much cheaper for chats with large message histories. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1264,8 +1264,10 @@ class ChatTable:
|
||||
self, id: str, user_id: str, db: Optional[AsyncSession] = None
|
||||
) -> list[TagModel]:
|
||||
async with get_async_db_context(db) as db:
|
||||
chat = await db.get(Chat, id)
|
||||
tag_ids = chat.meta.get('tags', [])
|
||||
stmt = select(Chat.meta).where(Chat.id == id)
|
||||
result = await db.execute(stmt)
|
||||
meta = result.scalar_one_or_none()
|
||||
tag_ids = (meta or {}).get('tags', [])
|
||||
return await Tags.get_tags_by_ids_and_user_id(tag_ids, user_id, db=db)
|
||||
|
||||
async def get_chat_list_by_user_id_and_tag_name(
|
||||
|
||||
Reference in New Issue
Block a user