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

This commit is contained in:
hh
2026-09-01 21:38:22 +02:00
parent 9c12628304
commit 1fa4f18a9b
35 changed files with 473 additions and 138 deletions
+10 -1
View File
@@ -30,10 +30,19 @@ RETURNING {_ACCOUNT_COLS}
""" # noqa: S608
_self_ids: dict[int, int] = {}
async def self_user_id(pool: asyncpg.Pool, account_id: int) -> int | None:
return await pool.fetchval(
cached = _self_ids.get(account_id)
if cached is not None:
return cached
tg_user_id = await pool.fetchval(
"SELECT tg_user_id FROM accounts WHERE account_id = $1", account_id
)
if tg_user_id is not None:
_self_ids[account_id] = tg_user_id
return tg_user_id
async def list_accounts(pool: asyncpg.Pool) -> list[AccountView]: