From ecdea8b487276f9c445884af1193df734205d079 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 14 Apr 2025 18:07:12 +1200 Subject: [PATCH 1/6] Update database --- composer.json | 2 +- composer.lock | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 3920351c06..ab8aa56c17 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.12.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.64.*", + "utopia-php/database": "dev-feat-bulk-callbacks as 0.64.2", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 5cd5122694..8e27ee0e98 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6a54c8bc4f9f14cd3883f55880864630", + "content-hash": "b5844f87eec4cd045d791d0a8e54965e", "packages": [ { "name": "adhocore/jwt", @@ -3497,16 +3497,16 @@ }, { "name": "utopia-php/database", - "version": "0.64.2", + "version": "dev-feat-bulk-callbacks", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "dc9c4a68c93e8bea2dfaa76d1ba308be539998bd" + "reference": "b6456ac11c4b00adea874f5dcba49f9904203563" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/dc9c4a68c93e8bea2dfaa76d1ba308be539998bd", - "reference": "dc9c4a68c93e8bea2dfaa76d1ba308be539998bd", + "url": "https://api.github.com/repos/utopia-php/database/zipball/b6456ac11c4b00adea874f5dcba49f9904203563", + "reference": "b6456ac11c4b00adea874f5dcba49f9904203563", "shasum": "" }, "require": { @@ -3547,9 +3547,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.64.2" + "source": "https://github.com/utopia-php/database/tree/feat-bulk-callbacks" }, - "time": "2025-04-09T07:53:05+00:00" + "time": "2025-04-14T05:53:57+00:00" }, { "name": "utopia-php/domains", @@ -8124,9 +8124,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-feat-bulk-callbacks", + "alias": "0.64.2", + "alias_normalized": "0.64.2.0" + } + ], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From 9a8ba13dbf0983066c47603d733dd09c512327cf Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 14 Apr 2025 18:18:10 +1200 Subject: [PATCH 2/6] Fix syntax --- src/Appwrite/Platform/Tasks/Maintenance.php | 2 +- src/Appwrite/Platform/Tasks/StatsResources.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Maintenance.php b/src/Appwrite/Platform/Tasks/Maintenance.php index 62f504acf0..7c8f9bda78 100644 --- a/src/Appwrite/Platform/Tasks/Maintenance.php +++ b/src/Appwrite/Platform/Tasks/Maintenance.php @@ -50,7 +50,7 @@ class Maintenance extends Action $dbForPlatform->foreach( 'projects', [ - Query::equal('region', System::getEnv('_APP_REGION', 'default')) + Query::equal('region', [System::getEnv('_APP_REGION', 'default')]) ], function (Document $project) use ($queueForDeletes, $usageStatsRetentionHourly) { $queueForDeletes diff --git a/src/Appwrite/Platform/Tasks/StatsResources.php b/src/Appwrite/Platform/Tasks/StatsResources.php index 88969ee2a4..ca2a6860ff 100644 --- a/src/Appwrite/Platform/Tasks/StatsResources.php +++ b/src/Appwrite/Platform/Tasks/StatsResources.php @@ -68,7 +68,7 @@ class StatsResources extends Action */ $this->foreachDocument($this->dbForPlatform, 'projects', [ Query::greaterThanEqual('accessedAt', DateTime::format($last24Hours)), - Query::equal('region', System::getEnv('_APP_REGION', 'default')) + Query::equal('region', [System::getEnv('_APP_REGION', 'default')]) ], function ($project) use ($queue) { $queue ->setProject($project) From 2a2bf7f154de7d9dca95e049890ef0c7848bd659 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 14 Apr 2025 18:23:35 +1200 Subject: [PATCH 3/6] Fix maintenance --- src/Appwrite/Platform/Tasks/Maintenance.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Maintenance.php b/src/Appwrite/Platform/Tasks/Maintenance.php index 7c8f9bda78..2df75b22a8 100644 --- a/src/Appwrite/Platform/Tasks/Maintenance.php +++ b/src/Appwrite/Platform/Tasks/Maintenance.php @@ -49,9 +49,6 @@ class Maintenance extends Action $dbForPlatform->foreach( 'projects', - [ - Query::equal('region', [System::getEnv('_APP_REGION', 'default')]) - ], function (Document $project) use ($queueForDeletes, $usageStatsRetentionHourly) { $queueForDeletes ->setType(DELETE_TYPE_MAINTENANCE) @@ -60,6 +57,7 @@ class Maintenance extends Action ->trigger(); }, [ + Query::equal('region', [System::getEnv('_APP_REGION', 'default')]), Query::limit(100), ] ); From 498f9e40c8423927b24ddd4b2a46b403bf294ec3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 14 Apr 2025 18:50:33 +1200 Subject: [PATCH 4/6] Update worker bulk method usage --- src/Appwrite/Platform/Workers/Databases.php | 15 ++++++--------- src/Appwrite/Platform/Workers/Deletes.php | 16 ++++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) 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"); } From 862664dd629221ec3126a1c6b0b2ad92622236c1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 14 Apr 2025 19:05:42 +1200 Subject: [PATCH 5/6] Format --- src/Appwrite/Platform/Workers/Deletes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 9d4e3e0f1e..4a2cb60d32 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -1051,7 +1051,7 @@ class Deletes extends Action * deleteDocuments uses a cursor, we need to add a unique order by field or use default */ try { - $count =$database->deleteDocuments( + $count = $database->deleteDocuments( $collection, $queries, Database::DELETE_BATCH_SIZE, From 950cc420a2334348a8ec69f762abb011b17b4f00 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 14 Apr 2025 19:40:51 +1200 Subject: [PATCH 6/6] Update database --- composer.json | 2 +- composer.lock | 39 +++++++++++++++------------------------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index ab8aa56c17..5b13227d2b 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.12.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-feat-bulk-callbacks as 0.64.2", + "utopia-php/database": "0.65.*", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 8e27ee0e98..9800d5fc9d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b5844f87eec4cd045d791d0a8e54965e", + "content-hash": "51ff891ef6cee8a3f8c4e5187b7fd479", "packages": [ { "name": "adhocore/jwt", @@ -3497,16 +3497,16 @@ }, { "name": "utopia-php/database", - "version": "dev-feat-bulk-callbacks", + "version": "0.65.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "b6456ac11c4b00adea874f5dcba49f9904203563" + "reference": "e589efdc5da1216523a758e8af358866d4fb563f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/b6456ac11c4b00adea874f5dcba49f9904203563", - "reference": "b6456ac11c4b00adea874f5dcba49f9904203563", + "url": "https://api.github.com/repos/utopia-php/database/zipball/e589efdc5da1216523a758e8af358866d4fb563f", + "reference": "e589efdc5da1216523a758e8af358866d4fb563f", "shasum": "" }, "require": { @@ -3547,9 +3547,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/feat-bulk-callbacks" + "source": "https://github.com/utopia-php/database/tree/0.65.0" }, - "time": "2025-04-14T05:53:57+00:00" + "time": "2025-04-14T07:39:01+00:00" }, { "name": "utopia-php/domains", @@ -3660,16 +3660,16 @@ }, { "name": "utopia-php/fetch", - "version": "0.4.0", + "version": "0.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/fetch.git", - "reference": "46e791ff6a95864517750b9df6bbf4a17e3c9c4e" + "reference": "65095dac14037db0c822fb5e209e5bd3187a0303" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/fetch/zipball/46e791ff6a95864517750b9df6bbf4a17e3c9c4e", - "reference": "46e791ff6a95864517750b9df6bbf4a17e3c9c4e", + "url": "https://api.github.com/repos/utopia-php/fetch/zipball/65095dac14037db0c822fb5e209e5bd3187a0303", + "reference": "65095dac14037db0c822fb5e209e5bd3187a0303", "shasum": "" }, "require": { @@ -3693,9 +3693,9 @@ "description": "A simple library that provides an interface for making HTTP Requests.", "support": { "issues": "https://github.com/utopia-php/fetch/issues", - "source": "https://github.com/utopia-php/fetch/tree/0.4.0" + "source": "https://github.com/utopia-php/fetch/tree/0.4.1" }, - "time": "2025-03-11T21:06:56+00:00" + "time": "2025-04-14T07:34:27+00:00" }, { "name": "utopia-php/framework", @@ -8124,18 +8124,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-feat-bulk-callbacks", - "alias": "0.64.2", - "alias_normalized": "0.64.2.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": {