mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-21 02:20:12 +00:00
Prisma operation.aggregate({ _min: { serverSeq } }) compiles to MIN()
over a `SELECT ... OFFSET 0` subquery. The OFFSET is a Postgres planner
optimization fence, so the (user_id, server_seq) index could not serve a
first-row seek and the query degraded to a per-user O(N) scan. Under a
client reconnect stampede this ran minutes inside the 60s interactive
download transaction, blowing the tx timeout (500s) and exhausting the
connection pool (cascading upload+download failures).
Replace it with findFirst ordered by serverSeq asc, which compiles to
ORDER BY server_seq ASC LIMIT 1 — a guaranteed index seek on the existing
unique (user_id, server_seq) index. Behaviour-preserving: same minSeq
value and same null-when-empty semantics.
Update both consuming specs (operation-download.service, gap-detection)
to the two-findFirst-call shape and add a regression test asserting the
indexed query is used and the aggregate path is not reintroduced.
|
||
|---|---|---|
| .. | ||
| sync | ||
| util | ||
| api.ts | ||
| auth-cache.ts | ||
| auth.ts | ||
| config.ts | ||
| db.ts | ||
| email-allowlist.ts | ||
| email.ts | ||
| index.ts | ||
| logger.ts | ||
| middleware.ts | ||
| pages.ts | ||
| passkey.ts | ||
| server.ts | ||
| test-routes.ts | ||