From e2bdc83d8171a7c343da5d790810013195ea0960 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 4 Sep 2025 03:01:45 +1200 Subject: [PATCH 1/3] Don't wait to return empty --- src/Database/Database.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 516949fe5..a600421c6 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4275,6 +4275,9 @@ public function updateDocument(string $collection, string $id, Document $documen $old = Authorization::skip(fn () => $this->silent( fn () => $this->getDocument($collection->getId(), $id, forUpdate: true) )); + if ($old->isEmpty()) { + return new Document(); + } $skipPermissionsUpdate = true; @@ -4414,10 +4417,6 @@ public function updateDocument(string $collection, string $id, Document $documen } } - if ($old->isEmpty()) { - return new Document(); - } - if ($shouldUpdate) { $document->setAttribute('$updatedAt', ($newUpdatedAt === null || !$this->preserveDates) ? $time : $newUpdatedAt); } From 42f35b7809155c875c50e60cb676e0268c329dcb Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 4 Sep 2025 03:24:02 +1200 Subject: [PATCH 2/3] Return empty on empty --- src/Database/Database.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Database/Database.php b/src/Database/Database.php index a600421c6..02211679b 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4449,6 +4449,10 @@ public function updateDocument(string $collection, string $id, Document $documen return $document; }); + if ($document->isEmpty()) { + return $document; + } + if ($this->resolveRelationships) { $document = $this->silent(fn () => $this->populateDocumentRelationships($collection, $document)); } From 82aa0e8523419dd832350255b52514d316e41f91 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 4 Sep 2025 03:28:02 +1200 Subject: [PATCH 3/3] Only trigger deleted if deleted --- src/Database/Database.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 02211679b..9b7a60ff0 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -5576,7 +5576,9 @@ public function deleteDocument(string $collection, string $id): bool return $result; }); - $this->trigger(self::EVENT_DOCUMENT_DELETE, $document); + if ($deleted) { + $this->trigger(self::EVENT_DOCUMENT_DELETE, $document); + } return $deleted; }