Skip to content

fix(databases): load transaction metadata once per database and table - #14190

Merged
HarshMN2345 merged 4 commits into
mainfrom
cursor/transaction-commit-metadata-cache-4f1b
Oct 28, 2026
Merged

HarshMN2345 merged 4 commits into
mainfrom
cursor/transaction-commit-metadata-cache-4f1b

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Transaction commit republished events by calling find() for the database document and the table document on every staged operation. find() is not served from the document cache, so a commit of N writes paid those two metadata queries N times (see #14176).

The event loop now keeps each database document, table document, and database adapter, and loads each one once. This is the same ??= memoization used when operations are staged. The usage metrics loop is unchanged.

TablesDB, DocumentsDB, and the legacy Databases API all commit through this action.

The schema map built with getCollection() while applying operations is a different document (internal id, attributes, indexes). Events need the project metadata document (public id, documentSecurity, permissions), so that map is not reused. The post-commit read of the changed row is unchanged.

Test Plan

  • php -l on the commit action and TransactionsBase
  • testCommitEventPayloadCarriesSurfaceIds now commits two tables and checks that each webhook payload carries its own database id and table id
  • Full end-to-end suite was not run in this environment (no Appwrite stack). CI runs the Databases and TablesDB transaction suites.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?
Open in Web Open in Cursor 

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/transaction-commit-metadata-cache-4f1b (after).

Metric Before After Change
🚀 Requests/sec 205.05 216.79 🟢 +5.7%
⏱️ Latency P50 81.92 ms 79.95 ms ⚪ -2.4%
⏱️ Latency P95 196.41 ms 185.91 ms 🟢 -5.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 79.95 185.91 13,680 216.79 -10.49
Account 148.96 286.88 720 12.05 -15.57
TablesDB 77.51 148.48 7,440 119.78 -11.46
Storage 73.56 174.89 3,600 59.9 +1.61
Functions 111.83 214.36 1,920 32.69 -9.34

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 420.74
account.prefs.update 398.76
account.name.update 376.54
tablesdb.rows.create 328.39
functions.create 319.62

@cursor
cursor Bot force-pushed the cursor/transaction-commit-metadata-cache-4f1b branch from 511a0aa to d3251d9 Compare October 7, 2026 09:28
The commit event loop called find() for the database and table documents
on every staged operation. find() is not served from the document cache,
so those lookups grew with the number of operations.

Keep each document next to the adapter cache, the same way staged
operations memoize a database and table. The commit event test covers
two tables so a reused document cannot be reported as the other table.

Fixes #14176
@cursor
cursor Bot force-pushed the cursor/transaction-commit-metadata-cache-4f1b branch from d3251d9 to d9eec6d Compare October 7, 2026 09:28
getLastRequestForProject returns an empty array when no delivery matches.
Fail there before reading payload fields.

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The transaction commit event loop now caches database metadata, collection metadata, and database adapters by their internal identifiers while publishing events. The E2E transaction test now commits operations across two collections and verifies each webhook payload uses the correct surface identifiers.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Memoizes database and collection metadata documents alongside the existing adapter cache during event publication.
tests/e2e/Services/Databases/Transactions/TransactionsBase.php Extends the event payload regression test to cover operations across two collections and updates ID helper casing.

Reviewed 2c1322c · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

…mmit-metadata-cache-4f1b

# Conflicts:
#	tests/e2e/Services/Databases/Transactions/TransactionsBase.php
@HarshMN2345
HarshMN2345 marked this pull request as ready for review October 28, 2026 12:52
@luxor-code-review

luxor-code-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR speeds up committing transaction operations that span multiple databases and collections by caching the resolved database document and collection metadata instead of re-resolving them per operation, and extends the transactions e2e suite with webhook-based verification of cross-collection commit behavior.

Files Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Adds per-commit memoization of database and collection document resolution, preserving skip-authorization boundaries.
tests/e2e/Services/Databases/Transactions/TransactionsBase.php Adds e2e assertions covering commit events across multiple collections and databases.

No findings met the review threshold; the refactor preserves the existing lookup semantics.

Reviewed commit: 2c1322c

@HarshMN2345
HarshMN2345 merged commit fe21322 into main Oct 28, 2026
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Transaction commit reloads metadata for every operation

1 participant