Skip to content

Commit 710d389

Browse files
committed
sort by attribute
1 parent ae7c96a commit 710d389

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/Database/Database.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9266,6 +9266,10 @@ public function getCacheKeys(string $collectionId, ?string $documentId = null, a
92669266
$collectionId
92679267
);
92689268

9269+
usort($selects, function ($a, $b) {
9270+
return strcmp($a->getAttribute(), $b->getAttribute());
9271+
});
9272+
92699273
if ($documentId) {
92709274
$documentKey = "{$collectionKey}:{$documentId}";
92719275

tests/unit/CacheKeyTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Utopia\Cache\Cache;
88
use Utopia\Database\Adapter;
99
use Utopia\Database\Database;
10+
use Utopia\Database\Query;
1011

1112
class CacheKeyTest extends TestCase
1213
{
@@ -51,8 +52,16 @@ public function testSelectOrderDoesNotAffectCacheKey(): void
5152
{
5253
$db = $this->createDatabase();
5354

54-
[, , $hashA] = $db->getCacheKeys('col', 'doc1', ['name', 'email']);
55-
[, , $hashB] = $db->getCacheKeys('col', 'doc1', ['email', 'name']);
55+
56+
[, , $hashA] = $db->getCacheKeys('col', 'doc1', [
57+
Query::select('email'),
58+
Query::select('name'),
59+
]);
60+
61+
[, , $hashB] = $db->getCacheKeys('col', 'doc1', [
62+
Query::select('name'),
63+
Query::select('email'),
64+
]);
5665

5766
$this->assertEquals($hashA, $hashB);
5867
}

0 commit comments

Comments
 (0)