perf(api,frontend): index hot queries, paginate chats, fix realtime
This commit is contained in:
@@ -6,6 +6,7 @@ from fastapi import APIRouter, Query
|
||||
from pydantic import BaseModel
|
||||
|
||||
from utils.jobs import enqueue
|
||||
from utils.policy import repository
|
||||
from utils.read import chats
|
||||
from utils.read.models import (
|
||||
DEFAULT_LIMIT,
|
||||
@@ -35,8 +36,24 @@ async def list_chats(
|
||||
account_id: AccountId,
|
||||
limit: Limit = DEFAULT_LIMIT,
|
||||
offset: Offset = 0,
|
||||
folder_id: Annotated[int | None, Query()] = None,
|
||||
search: Annotated[str | None, Query()] = None,
|
||||
) -> list[ChatListItem]:
|
||||
return await chats.list_chats(pool, account_id, Page(limit=limit, offset=offset))
|
||||
folder = (
|
||||
await repository.get_folder(pool, account_id, folder_id)
|
||||
if folder_id is not None
|
||||
else None
|
||||
)
|
||||
return await chats.list_chats(
|
||||
pool, account_id, Page(limit=limit, offset=offset), folder=folder, search=search
|
||||
)
|
||||
|
||||
|
||||
@router.get("/chats/{chat_id}")
|
||||
async def get_chat(
|
||||
pool: FromDishka[asyncpg.Pool], chat_id: int, account_id: AccountId
|
||||
) -> ChatListItem | None:
|
||||
return await chats.get_chat(pool, account_id, chat_id)
|
||||
|
||||
|
||||
@router.get("/chats/{chat_id}/messages")
|
||||
|
||||
Reference in New Issue
Block a user