Postgres pool, review round 1: nested transactions, account mail after commit

P-1: a transaction begun inside another one (a hook calling the Local API
without req) no longer queues behind its caller. An AsyncLocalStorage mark set
when a transaction begins lets the inner one through at once, without a
place, but never into the last connection (a second level may take that
one). If the mark is lost, a queue that has not moved for a second admits
its newest waiter. connectionReserve: false now admits everything, as
before. Measured on Postgres 17: 9, 12 and 30 such submissions finish
(before: stuck from 9).

P-2: Payload's "forgot password" and "verify your e-mail" through
mailAdapter() go out right after their transaction commits
(mail.accountMailAfterCommit, default on). With the relay hanging,
30 resets + 30 submissions finish in about 11 s instead of 43.5 s.

P-3: Postgres tests for the "not confirmed" file result after commit, a
caller's outer transaction rolled back or committed, the relay hanging,
and the nested rows; deployment.md has the measured table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 01:19:27 +01:00
co-authored by Claude Opus 5.5
parent 32bb542e8e
commit 4efadb21d5
18 changed files with 534 additions and 107 deletions
+6
View File
@@ -32,6 +32,7 @@ import { buildConstructionFields } from './modules/construction/fields.js'
import { buildArchiveFields } from './modules/content/index.js'
import { defaultConnectionReserve, poolSize, watchTransactions } from './modules/database/transactions.js'
import { buildDoctorEndpoint } from './modules/doctor/status.js'
import { withAccountMailAfterCommit } from './modules/email/accountMailAfterCommit.js'
import { GRAPH_DEPRECATION_NOTICE, graphAvailable } from './modules/email/mailAdapter.js'
import { withAccountMailMark } from './modules/email/relay/accountMail.js'
import { relayConfirmEndpoint } from './modules/email/relay/confirm.js'
@@ -757,6 +758,11 @@ export const iapl = (options: IaplOptions): Plugin => {
...config.custom,
iapl: { ...iaplCustom, mail: { ...(options.mail?.graphDeprecationWarning === false ? { graphDeprecationWarning: false } : {}), relay: relay === false ? false : (relay ?? {}) } },
}
// "Forgot password" and "verify your e-mail" through mailAdapter(): sent right after their transaction
// commits, not inside it (mail.accountMailAfterCommit; docs/deployment.md §4.3a).
if (options.mail?.accountMailAfterCommit !== false) {
config.collections = (config.collections ?? []).map((c) => (c.auth ? withAccountMailAfterCommit(c) : c))
}
if (relay !== false) {
// The public route the service calls a site back at (404 unless this site just started an
// enrolment), and the admin-only routes of the state block on the e-mail tab.