Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -5376,7 +5376,7 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
$cursor = $grouped['cursor'];

if (!empty($cursor) && $cursor->getCollection() !== $collection->getId()) {
throw new DatabaseException("cursor Document must be from the same Collection.");
throw new DatabaseException("Cursor document must be from the same Collection.");
}

$documents = $this->withTransaction(function () use ($collection, $queries, $batchSize, $limit, $cursor) {
Expand Down Expand Up @@ -5413,12 +5413,14 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
break;
}

$documents = array_merge($affectedDocuments, $documents);
$documents = \array_merge($affectedDocuments, $documents);

foreach ($affectedDocuments as $document) {
// Delete Relationships
if ($this->resolveRelationships) {
$document = $this->silent(fn () => $this->deleteDocumentRelationships($collection, $document));
$document = $this->silent(fn () => $this->deleteDocumentRelationships(
$collection,
$document
));
}

// Check if document was updated after the request timestamp
Expand All @@ -5431,8 +5433,6 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
if (!\is_null($this->timestamp) && $oldUpdatedAt > $this->timestamp) {
throw new ConflictException('Document was updated after the request timestamp');
}

$this->purgeCachedDocument($collection->getId(), $document->getId());
}

if (count($affectedDocuments) < $batchSize) {
Expand All @@ -5448,11 +5448,6 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
return [];
}

$this->trigger(self::EVENT_DOCUMENTS_DELETE, new Document([
'$collection' => $collection->getId(),
'modified' => count($documents)
]));

foreach (\array_chunk($documents, $batchSize) as $chunk) {
$this->adapter->deleteDocuments(
$collection->getId(),
Expand All @@ -5463,6 +5458,15 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
return $documents;
});

foreach ($documents as $document) {
$this->purgeCachedDocument($collection->getId(), $document->getId());
}

$this->trigger(self::EVENT_DOCUMENTS_DELETE, new Document([
'$collection' => $collection->getId(),
'modified' => count($documents)
]));

return $documents;
}

Expand Down
Loading