Skip to content

🐛 Bug Report: Transaction commit reloads metadata for every operation #14176

Closed

Description

@JoshiJoshiJoshi

👟 Reproduction steps

  1. Create a transaction, stage N update operations on N different rows of one table (POST /v1/tablesdb/transactions/{id}/operations).
  2. Commit it (PATCH /v1/tablesdb/transactions/{id} with commit: true) and log the SQL statements (log_min_duration_statement = 0).

👍 Expected behavior

After the operations are applied, the event loop needs the database and table document once per database/table, not once per operation.

👎 Actual Behavior

For every staged operation the commit runs two additional uncached find queries on the project's metadata tables, after the data has been committed:

SELECT "main".* FROM "appwrite"."_1_databases" AS "main" WHERE (("main"."_id" = '2')) ORDER BY "_id" ASC LIMIT 1 OFFSET 0;
SELECT "main".* FROM "appwrite"."_1_database_2" AS "main" WHERE (("main"."_id" = '126')) ORDER BY "_id" ASC LIMIT 1 OFFSET 0;
SELECT "main".* FROM "appwrite"."_1_database_2_collection_126" AS "main" WHERE "main"."_uid" = 'r0031'
... repeated for each of the 10 operations

In the post-commit loop of Transactions/Update.php a $dbCache keeps the database adapter per databaseInternalId (the comment says "using a dbCache so only one time database is set with databaseInternalId"), but right after it $database and $collection are fetched again with findOne('databases', …) and findOne('database_' . $databaseInternalId, …) for every operation (L402–L414). find is never served from the document cache, so each lookup is a database roundtrip. main still has the same code.

Measured with a local probe that only memoises these two lookups per ID (two API nodes, Postgres on a separate node, A/B/A/B):

stock memoised stock memoised stock
commit with 10 operations, p50 (serial) 125 ms 86 ms 112 ms 95 ms 117 ms
commit with 100 operations, p50 (serial) 906 ms 621 ms 848 ms 783 ms 900 ms
throughput, 8 clients × 10 operations per transaction 431 ops/s 527 ops/s 442 ops/s 522 ops/s 456 ops/s
SQL statements for one commit with 10 operations 187 130 181 133 184

So roughly 20–30 % of the commit time of a transaction comes from these repeated lookups, and it grows linearly with the number of operations (about 9 ms per operation in total today).

🎲 Appwrite version

2.3.0

💻 Operating system

Linux (Debian 12), Docker

🧱 Your Environment

Self-hosted Appwrite 2.3.0, Postgres adapter (PostgreSQL 18), two API nodes, Postgres on a separate node.

💡 Suggested fix

Look up $database and $collection once per databaseInternalId / collectionInternalId (e.g. keep them next to $dbCache, or reuse the $collections map built while applying the operations), or use getDocument by ID so the document cache applies. The per-operation getDocument of the changed row for the event payload could also reuse the document returned while applying the operation.

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Code of Conduct?

  • I have read the Code of Conduct

Activity

  1. added
    product / databases
    sdk / cli
    on Oct 6, 2026
  2. added 2 commits that reference this issue on Oct 7, 2026
    d3251d9
    d9eec6d
  3. JoshiJoshiJoshi commented on Oct 28, 2026

    @JoshiJoshiJoshi
    Author

    KEEP IT COMING @HarshMN2345
    FIX THEM ALL, LET'S GOOOOOOOOOO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / databasessdk / cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions