fix(db): take the write lock in every transaction that writes

UnitOfWork took the engine's write lock, but four repositories opened
transactions of their own: the demo addon set, the plugin user erasure's
savepoints, and the plugin metadata and scheduler cap checks. On Postgres
those ran beside the others on the pool.

writeTransaction (src/db/engine/write-transaction.ts) is now the one
transaction that writes: UnitOfWork wraps it, and the demo seed and reset,
which run outside the container, call it with the engine the environment
names. The capped plugin writes run in their caller's unit of work instead
of a transaction of their own, and the plugin erasure runs in the erasure's
transaction without savepoints, since its three tables come with the
migrations on both engines. lint:tx counts writeTransaction as a
transaction.
This commit is contained in:
Maurice
2026-11-17 14:14:29 +01:00
parent 981052224c
commit 61ea6b648c
9 changed files with 107 additions and 64 deletions
+5 -3
View File
@@ -19,8 +19,8 @@
* A method's "write units" are then counted over its body:
* - a call to a write, on a constructor-injected field (`this.trips.x()`)
* or on its own class (`this.x()`), is one unit;
* - a `.transactional(...)` call that holds any write is one unit, however
* many writes it holds;
* - a `.transactional(...)` or `writeTransaction(...)` call that holds any
* write is one unit, however many writes it holds;
* - a call to a method of another class that is itself reported counts as
* one unit here (the fault is reported once, where it lives);
* - a write inside a loop, or inside a callback handed to forEach/map/
@@ -343,7 +343,9 @@ export function analyse(classes) {
const receiver = ts.isPropertyAccessExpression(callee)
? count(cls, callee.expression, covered)
: count(cls, callee, covered);
if (method === 'transactional') {
// `writeTransaction(em, engine, fn)` (src/db/engine/write-transaction.ts) is the
// transaction `UnitOfWork.transactional` opens, for code outside the container.
if (method === 'transactional' || (ts.isIdentifier(callee) && callee.text === 'writeTransaction')) {
let inner = 0;
frames.push([]); // what runs inside is one unit, not a list of its own
for (const arg of node.arguments) inner += count(cls, arg, true);