mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Attempt to reuse db connections
This commit is contained in:
+12
-2
@@ -56,19 +56,29 @@ CLI::setResource('dbForConsole', function ($pools, $cache) {
|
||||
}, ['pools', 'cache']);
|
||||
|
||||
CLI::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, $cache) {
|
||||
$getProjectDB = function (Document $project) use ($pools, $dbForConsole, $cache) {
|
||||
$databases = [];
|
||||
|
||||
$getProjectDB = function (Document $project) use ($pools, $dbForConsole, $cache, &$databases) {
|
||||
if ($project->isEmpty() || $project->getId() === 'console') {
|
||||
return $dbForConsole;
|
||||
}
|
||||
|
||||
$databaseName = $project->getAttribute('database');
|
||||
|
||||
if(isset($databases[$databaseName])) {
|
||||
return $databases[$databaseName];
|
||||
}
|
||||
|
||||
$dbAdapter = $pools
|
||||
->get($project->getAttribute('database'))
|
||||
->get($databaseName)
|
||||
->pop()
|
||||
->getResource();
|
||||
|
||||
$database = new Database($dbAdapter, $cache);
|
||||
$database->setNamespace('_' . $project->getInternalId());
|
||||
|
||||
$databases[$databaseName] = $database;
|
||||
|
||||
return $database;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user