Repository navigation
fix(databases): emit row events for bulk operations in a transaction - #14383
Conversation
The commit collected nothing for bulkCreate, bulkUpdate, bulkUpsert and bulkDelete, so webhooks, functions and realtime never saw those rows. Collect each bulk operation's rows from its onNext callback and send one create, update, upsert or delete event per row after the commit, like the direct bulk endpoints.
|
Review complete. 🟡 1 medium 📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Cap bulk transaction events like direct bulk endpoints · Update.php:545–598 · // src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php
545 foreach ($documentsToTrigger as $doc) {
546 $doc->removeAttribute('$collection');
547 $doc->removeAttribute('$tenant');
548
549 // Match the key set processDocument() gives every other row and document
550 // event: the synthetic $databaseId, plus whichever of $tableId or
551 // $collectionId belongs to the surface that was called.
552 $payload = $doc->getArrayCopy();
553 $payload['$databaseId'] = $database->getId();
554 $payload['$' . $groupId] = $collection->getId();
555
556 $queueForEventsThe new event loop for bulk transaction operations emits one realtime, function, and webhook event per affected document with no batch cap (Transactions/Update.php:545-598), while the equivalent direct bulk endpoints cap collected documents at This PR extends the transaction commit endpoint so bulk operations staged in a transaction now emit per-document events (create/update/upsert/delete) after commit, mirroring the direct bulk endpoints, with clones of affected documents captured at operation time to protect event payloads from later state mutation.
Reviewed commit: 1be8878 |
🔵 Tier A · Mergeable after minor fixes
Transaction commits now retain per-operation row snapshots for bulk create, update, upsert, and delete, then emit one matching event per affected row after commit. The commit closure also shares the current attribute/change values with its outer exception handling so increment and decrement failures can be translated using the operation's details. Latest changes: The newest change updates the commit closure captures to share currentAttribute and currentChange with the outer error handling and removes unused authorization-related captures.
Fix with agent prompt### Issue 1
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php:520
**Add e2e coverage for transaction bulk events**
The transaction tests verify bulk operations' persisted results, but `testCommitEventPayloadCarriesSurfaceIds()` covers only a scalar create. Without event assertions for these new bulk paths, regressions in action names, row payloads, or snapshots across later operations can pass the suite unnoticed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 1
⏳ Still open from earlier reviews · 1
Merged |
| break; | ||
| case 'bulkCreate': | ||
| $eventAction = 'create'; | ||
| $documentsToTrigger = $bulkDocuments[$operation->getId()]; |
There was a problem hiding this comment.
Add e2e coverage for transaction bulk events
The transaction tests verify bulk operations' persisted results, but testCommitEventPayloadCarriesSurfaceIds() covers only a scalar create. Without event assertions for these new bulk paths, regressions in action names, row payloads, or snapshots across later operations can pass the suite unnoticed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php
Line: 520
Comment:
**Add e2e coverage for transaction bulk events**
The transaction tests verify bulk operations' persisted results, but `testCommitEventPayloadCarriesSurfaceIds()` covers only a scalar create. Without event assertions for these new bulk paths, regressions in action names, row payloads, or snapshots across later operations can pass the suite unnoticed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
# Conflicts: # src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php
What changed
Committing a transaction sent no events for its
bulkCreate,bulkUpdate,bulkUpsertandbulkDeleteoperations, so webhooks, functions and realtime never saw those rows.Transactions/Update.phpcollect the rows they write from theironNextcallbacks. They keep a copy, because later operations change state documents in place.create,update,upsertordeleteevent, with the same payload keys as the direct bulk endpoints.upsertmatchesupsertRows.Verified
Local stack running this branch (TablesDB on Postgres), webhook on
databases.<db>.tables.<table>.rows.*, 3 rows per operation:createRows/updateRows/upsertRows/deleteRowsbulkCreate/bulkUpdate/bulkUpsert/bulkDeletecreate+updatebulkCreate,bulkUpdateandbulkDeleteon the same rows: the create payloads carry the rows as created, the update payloads the updated values.TablesDBTransactionsCustomServerTest,TablesDBTransactionsCustomClientTestandLegacyTransactionsCustomServerTestpass.Fixes #14219