perf(*): bound list queries, batch fetches, harden media downloads
This commit is contained in:
1 parent
9c12628304
commit
1fa4f18a9b
35 files changed
+473
-138
No files matched your search
@@ -9,12 +9,22 @@ JOBS_CHANGED_CHANNEL = "jobs_changed"
|
||||
async def enqueue(
|
||||
pool: asyncpg.Pool, account_id: int, kind: str, params: dict[str, Any]
|
||||
) -> int:
|
||||
params_json = json.dumps(params)
|
||||
existing = await pool.fetchval(
|
||||
"SELECT id FROM jobs WHERE account_id = $1 AND kind = $2 "
|
||||
"AND params = $3::jsonb AND status IN ('pending', 'running') LIMIT 1",
|
||||
account_id,
|
||||
kind,
|
||||
params_json,
|
||||
)
|
||||
if existing is not None:
|
||||
return existing
|
||||
job_id = await pool.fetchval(
|
||||
"INSERT INTO jobs (account_id, kind, params) "
|
||||
"VALUES ($1, $2, $3::jsonb) RETURNING id",
|
||||
account_id,
|
||||
kind,
|
||||
json.dumps(params),
|
||||
params_json,
|
||||
)
|
||||
await pool.execute(f"NOTIFY {JOBS_CHANGED_CHANNEL}")
|
||||
return job_id
|
||||
Reference in new issue
Block a user