Repository navigation
Description
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 throughListCache::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:
- Create a table with no rows, then call
GET /v1/tablesdb/{db}/tables/{table}/rows?ttl=600. You gettotal: 0,X-Appwrite-Cache: miss. - Create row
e1. - 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:
- 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. - 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
ArnabChatterjee20k commentedon Nov 17, 2026
Opened by mistake. The finding is recorded on #15707 instead.