From b031e13997005c437004b1ade7e65fe0df006fcc Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Tue, 15 Nov 2022 11:39:24 +0100 Subject: [PATCH] Improve reclaim of pools in schedule --- app/cli.php | 10 +++++----- src/Appwrite/Platform/Tasks/schedule.php | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/cli.php b/app/cli.php index b176326191..3546674a13 100644 --- a/app/cli.php +++ b/app/cli.php @@ -61,16 +61,16 @@ CLI::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, return $dbForConsole; } - $dbAdapter = $pools + $connection = $pools ->get($project->getAttribute('database')) - ->pop() - ->getResource() - ; + ->pop(); + + $dbAdapter = $connection->getResource(); $database = new Database($dbAdapter, $cache); $database->setNamespace('_' . $project->getInternalId()); - return $database; + return [ $database, fn() => $connection->claim() ]; }; return $getProjectDB; diff --git a/src/Appwrite/Platform/Tasks/schedule.php b/src/Appwrite/Platform/Tasks/schedule.php index e070206405..0d88de1d05 100644 --- a/src/Appwrite/Platform/Tasks/schedule.php +++ b/src/Appwrite/Platform/Tasks/schedule.php @@ -49,7 +49,10 @@ class Schedule extends Action */ $getSchedule = function (Document $schedule) use ($dbForConsole, $getProjectDB): array { $project = $dbForConsole->getDocument('projects', $schedule->getAttribute('projectId')); - $function = $getProjectDB($project)->getDocument('functions', $schedule->getAttribute('resourceId')); + + [ $database, $reclaim ] = $getProjectDB($project); + $function = $database->getDocument('functions', $schedule->getAttribute('resourceId')); + $reclaim(); return [ 'resourceId' => $schedule->getAttribute('resourceId'),