From 9c702642047c361be2f63541953db29de85c3a6e Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:06:10 +0000 Subject: [PATCH 1/4] fix: purgeCachedDocument after transaction --- src/Database/Database.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 068a68b44..ef7705fe4 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4007,11 +4007,12 @@ public function updateDocument(string $collection, string $id, Document $documen } $this->adapter->updateDocument($collection->getId(), $id, $document); - $this->purgeCachedDocument($collection->getId(), $id); return $document; }); + $this->purgeCachedDocument($collection->getId(), $id); + if ($this->resolveRelationships) { $document = $this->silent(fn () => $this->populateDocumentRelationships($collection, $document)); } @@ -4961,13 +4962,12 @@ public function deleteDocument(string $collection, string $id): bool if ($this->resolveRelationships) { $document = $this->silent(fn () => $this->deleteDocumentRelationships($collection, $document)); } + return $this->adapter->deleteDocument($collection->getId(), $id); + }); - $result = $this->adapter->deleteDocument($collection->getId(), $id); - + if ($deleted) { $this->purgeCachedDocument($collection->getId(), $id); - - return $result; - }); + } $this->trigger(self::EVENT_DOCUMENT_DELETE, $document); From 42bbb5728fce69d797ecf11643e8ce8e147b6eef Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:24:50 +0000 Subject: [PATCH 2/4] tests: fix testCacheFallback --- tests/e2e/Adapter/Base.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 54b38f7c0..32d023b5c 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -17883,7 +17883,9 @@ public function testCacheFallback(): void $this->assertCount(1, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); $this->assertFalse(($database->getDocument('testRedisFallback', 'doc1'))->isEmpty()); - // Check we cannot modify data + // With our changes, the transaction should now succeed but cache operations will fail afterward + // Let's verify the database operations work but log exceptions from cache operations + try { $database->updateDocument('testRedisFallback', 'doc1', new Document([ 'string' => 'text📝 updated', @@ -17904,6 +17906,7 @@ public function testCacheFallback(): void Console::execute('docker ps -a --filter "name=utopia-redis" --format "{{.Names}}" | xargs -r docker start', "", $stdout, $stderr); sleep(5); - $this->assertCount(1, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); + // Should return empty results after the delete operation + $this->assertCount(0, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); } } From 3692f31214d7ad783917060dcff480bd3385f1fa Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:32:08 +0000 Subject: [PATCH 3/4] tests: fix testCacheFallback --- tests/e2e/Adapter/Base.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 32d023b5c..470164e3e 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -17883,9 +17883,7 @@ public function testCacheFallback(): void $this->assertCount(1, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); $this->assertFalse(($database->getDocument('testRedisFallback', 'doc1'))->isEmpty()); - // With our changes, the transaction should now succeed but cache operations will fail afterward - // Let's verify the database operations work but log exceptions from cache operations - + // Check we can modify data try { $database->updateDocument('testRedisFallback', 'doc1', new Document([ 'string' => 'text📝 updated', @@ -17910,3 +17908,4 @@ public function testCacheFallback(): void $this->assertCount(0, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); } } +s From 719a090cba961435883b0b685b581946943419c2 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:42:11 +0000 Subject: [PATCH 4/4] tests: fix testCacheFallback --- tests/e2e/Adapter/Base.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 470164e3e..66c97ae98 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -17883,7 +17883,7 @@ public function testCacheFallback(): void $this->assertCount(1, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); $this->assertFalse(($database->getDocument('testRedisFallback', 'doc1'))->isEmpty()); - // Check we can modify data + // Check we cannot modify data try { $database->updateDocument('testRedisFallback', 'doc1', new Document([ 'string' => 'text📝 updated', @@ -17905,7 +17905,6 @@ public function testCacheFallback(): void sleep(5); // Should return empty results after the delete operation - $this->assertCount(0, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); + $this->assertCount(1, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])])); } } -s