Commit 6085a0d
fix(objectql): thread transaction through beforeUpdate/beforeDelete hooks
Prior to this fix, calling engine.update or engine.delete inside an
engine.transaction() block would deadlock for ~60s on SQLite (knex
pool=1) before completing. Root cause: the built-in
sys_fetch_previous_update / sys_fetch_previous_delete hooks and the
audit captureBefore hook both issue a findOne to snapshot the row,
but neither carries the active transaction through. On a single-
connection driver this read waits the full acquireConnectionTimeout
for a fresh connection that never comes (the outer transaction owns
the only one), then eventually proceeds when the trx commits.
Concrete impact: convertLead (4 ops in a single transaction) took
60.1s end-to-end even though the actual SQL took <50ms.
Fix:
* sys_fetch_previous_update / delete hooks (packages/objectql/
src/plugin.ts) now pass context.isSystem + the open trx when
hookCtx.transaction is set.
* Audit captureBefore (packages/plugins/plugin-audit/src/audit-
writers.ts) now prefers ctx.ql.findOne with isSystem + trx and
only falls back to api.sudo() when no engine ref is available.
Verified: 3 sequential convertLead calls now complete in 77ms-116ms
(was 60.1s each). All 232 objectql tests, 55 plugin-security tests,
and 215 metadata tests still pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 6af96d1 commit 6085a0d
3 files changed
Lines changed: 32 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
404 | 410 | | |
405 | 411 | | |
406 | 412 | | |
| |||
419 | 425 | | |
420 | 426 | | |
421 | 427 | | |
422 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
423 | 435 | | |
424 | 436 | | |
425 | 437 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1101 | 1101 | | |
1102 | 1102 | | |
1103 | 1103 | | |
1104 | | - | |
1105 | 1104 | | |
1106 | 1105 | | |
1107 | 1106 | | |
| |||
1125 | 1124 | | |
1126 | 1125 | | |
1127 | 1126 | | |
1128 | | - | |
1129 | 1127 | | |
1130 | 1128 | | |
1131 | 1129 | | |
| |||
1152 | 1150 | | |
1153 | 1151 | | |
1154 | 1152 | | |
1155 | | - | |
1156 | 1153 | | |
1157 | 1154 | | |
1158 | 1155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | | - | |
125 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
126 | 142 | | |
127 | 143 | | |
128 | 144 | | |
| |||
0 commit comments