perf(*): bound list queries, batch fetches, harden media downloads
This commit is contained in:
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user