perf(*): bound list queries, batch fetches, harden media downloads

This commit is contained in:
hh committed 2026-09-01 21:38:22 +02:00
1 parent 9c12628304
commit 1fa4f18a9b
35 files changed
+473 -138

No files matched your search

+13 -2
View File
@@ -8,6 +8,7 @@ from fastapi import APIRouter, HTTPException, Query
from pydantic import BaseModel
from utils.jobs import enqueue
from utils.read.models import DEFAULT_LIMIT, Page
router = APIRouter(prefix="/api", tags=["backfill"], route_class=DishkaRoute)
@@ -130,16 +131,26 @@ async def list_jobs(
pool: FromDishka[asyncpg.Pool],
account_id: Annotated[int, Query()],
status: Annotated[str | None, Query()] = None,
limit: Annotated[int, Query()] = DEFAULT_LIMIT,
offset: Annotated[int, Query()] = 0,
) -> list[JobView]:
page = Page(limit=limit, offset=offset)
if status is None:
rows = await pool.fetch(
"SELECT * FROM jobs WHERE account_id = $1 ORDER BY id DESC", account_id
"SELECT * FROM jobs WHERE account_id = $1 "
"ORDER BY id DESC LIMIT $2 OFFSET $3",
account_id,
page.capped_limit,
page.offset,
)
else:
rows = await pool.fetch(
"SELECT * FROM jobs WHERE account_id = $1 AND status = $2 ORDER BY id DESC",
"SELECT * FROM jobs WHERE account_id = $1 AND status = $2 "
"ORDER BY id DESC LIMIT $3 OFFSET $4",
account_id,
status,
page.capped_limit,
page.offset,
)
return [_to_view(row) for row in rows]