From d5b2f9725224c8e2268df20cac3f364ccc7924cb Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 26 Feb 2026 23:07:24 +1300 Subject: [PATCH] fix: use md5 hash of attributes/indexes instead of counts in cache key Counts alone miss delete/re-add scenarios where the count stays the same but the schema is different. MD5 of the full attribute and index arrays captures any schema change. Co-Authored-By: Claude Opus 4.6 --- .../Http/Databases/Collections/Documents/XList.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index 52c6d2af16..e5cd732e17 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -142,18 +142,16 @@ class XList extends Action $hostname = $dbForProject->getAdapter()->getHostname(); $roles = $dbForProject->getAuthorization()->getRoles(); $collectionUpdatedAt = $collection->getAttribute('$updatedAt', ''); - $attributeCount = \count($collection->getAttribute('attributes', [])); - $indexCount = \count($collection->getAttribute('indexes', [])); + $schemaHash = \md5(\json_encode($collection->getAttribute('attributes', [])) . \json_encode($collection->getAttribute('indexes', []))); $cacheKeyBase = \sprintf( - '%s-cache-%s:%s:%s:collection:%s:%s:%d:%d:user:%s:%s', + '%s-cache-%s:%s:%s:collection:%s:%s:%s:user:%s:%s', $dbForProject->getCacheName(), $hostname ?? '', $dbForProject->getNamespace(), $dbForProject->getTenant(), $collectionId, $collectionUpdatedAt, - $attributeCount, - $indexCount, + $schemaHash, \md5(\json_encode($roles)), \md5(\json_encode($serializedQueries)) );