Skip to content

databases: ttl list cache keeps a total of 0 after the first row is added #15718

Closed as not planned

Description

@ArnabChatterjee20k

Problem

When list caching is on (ttl > 0 on list documents or list rows), an empty result caches its total but not its rows. After the first row is added, the next list request returns the new row with a stale total of 0 until the TTL runs out.

In src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php (TablesDB Rows\XList extends it, so both APIs are affected):

  • Rows: saved only when the result isn't empty (if ($documents !== []), around lines 213-219). An empty page is never cached, so every request queries the database again.
  • Total: saved every time (around lines 224-230), including "0" for an empty result. It goes through ListCache::save() → Cache::saveMany(), which stores empty values.
  • Invalidation: by design, row writes don't clear the list cache; only schema and permission changes do.

So once a table that was empty gets a row, the rows are read fresh, but the total still comes from the cache.

Reproduction

Seen on staging fra (cloud-fra1-stg) and in a unit run against the current main:

  1. Create a table with no rows, then call GET /v1/tablesdb/{db}/tables/{table}/rows?ttl=600. You get total: 0, X-Appwrite-Cache: miss.
  2. Create row e1.
  3. Call the same list again. You get rows: ["e1"], total: 0.
PASS list empty ttl=600 rows has e1 (empty never cached)  200  [e1] cache=miss
NOTE list empty ttl=600 total (cached '0', row writes don't purge)  0 cache=hit

This isn't caused by #15704 (utopia-php/cache 8.0.0). The same result shows on builds from before and after that change.

Possible fixes

Cache the rows and the total together, so they never disagree:

  1. Cache the empty page too. Drop the $documents !== [] guard, so an empty result caches its rows and its total, as a non-empty one does. This follows the documented contract ("row writes do not invalidate"): the first row appears once the TTL runs out, and the response is never internally inconsistent.
  2. Cache nothing for an empty result. Skip saving the total when the rows aren't cached, so an empty list always reads both fresh.

Option 1 matches how non-empty lists already behave. Option 2 keeps a newly added row visible straight away, at the cost of a database query per request for empty lists. Whichever is picked needs an E2E test: empty list, add a row, list again with ttl, and assert the rows and total agree.

Activity

  1. added
    product / databases
    on Nov 17, 2026
  2. ArnabChatterjee20k commented on Nov 17, 2026

    @ArnabChatterjee20k
    MemberAuthor

    Opened by mistake. The finding is recorded on #15707 instead.

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 / databases

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions