diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 44738b557c..1b3311b756 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -563,22 +563,19 @@ class Databases extends Action $start = \microtime(true); try { - $documents = $database->deleteDocuments($collectionId, $queries); + $count = $database->deleteDocuments( + $collectionId, + $queries, + Database::DELETE_BATCH_SIZE, + $callback + ); } catch (\Throwable $th) { $tenant = $database->getSharedTables() ? 'Tenant:'.$database->getTenant() : ''; Console::error("Failed to delete documents for collection:{$database->getNamespace()}_{$collectionId} {$tenant} :{$th->getMessage()}"); return; } - if (\is_callable($callback)) { - foreach ($documents as $document) { - $callback($document); - } - } - $end = \microtime(true); - $count = \count($documents); - Console::info("Deleted {$count} documents by group in " . ($end - $start) . " seconds"); } diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 5be865f42b..9d4e3e0f1e 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -1050,24 +1050,20 @@ class Deletes extends Action /** * deleteDocuments uses a cursor, we need to add a unique order by field or use default */ - try { - $documents = $database->deleteDocuments($collection, $queries); + $count =$database->deleteDocuments( + $collection, + $queries, + Database::DELETE_BATCH_SIZE, + $callback + ); } catch (Throwable $th) { $tenant = $database->getSharedTables() ? 'Tenant:'.$database->getTenant() : ''; Console::error("Failed to delete documents for collection:{$database->getNamespace()}_{$collection} {$tenant} :{$th->getMessage()}"); return; } - if (\is_callable($callback)) { - foreach ($documents as $document) { - $callback($document); - } - } - $end = \microtime(true); - $count = \count($documents); - Console::info("Deleted {$count} documents by group in " . ($end - $start) . " seconds"); }