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
+14 -3
View File
@@ -39,6 +39,7 @@ export async function site(name: string, { emailsInTransaction = false } = {}) {
{ slug: 'users', auth: true, fields: [] },
{ slug: 'media', fields: [], upload: { staticDir: path.join(os.tmpdir(), 'iapl-test-pool-media') } },
{ slug: 'pages', access: { read: () => true }, fields: [{ name: 'title', type: 'text' }] },
{ slug: 'log', fields: [{ name: 'note', type: 'text' }] },
],
db: testDatabase(name),
editor: lexicalEditor(),
@@ -52,9 +53,19 @@ export async function site(name: string, { emailsInTransaction = false } = {}) {
formSubmissionOverrides: {
hooks: {
// a later hook that fails: the submission is rolled back
afterChange: [({ doc }) => {
if ((doc as { submissionData?: { value?: string }[] }).submissionData?.some((row) => row.value === 'roll-me-back')) {throw new Error('rolled back on purpose')}
}],
afterChange: [
({ doc }) => {
if ((doc as { submissionData?: { value?: string }[] }).submissionData?.some((row) => row.value === 'roll-me-back')) {throw new Error('rolled back on purpose')}
},
// a project's hook that writes through the Local API WITHOUT `req`: a transaction of its own,
// begun while the submission's is still open
async ({ doc, req }) => {
const rows = (doc as { id: number | string; submissionData?: { value?: string }[] }).submissionData ?? []
if (!rows.some((row) => row.value?.startsWith('nested-'))) {return}
await new Promise((resolve) => setTimeout(resolve, 50))
await req.payload.create({ collection: 'log' as never, data: { note: `submission ${doc.id}` } as never })
},
],
},
},
},