Merge pull request #9213 from appwrite/fix-dead-connections

Fix dead connections
This commit is contained in:
Jake Barnby
2025-01-15 15:27:42 +13:00
parent 7adf81708c
commit 3f620bbc44
4 changed files with 78 additions and 28 deletions
+23 -8
View File
@@ -74,6 +74,7 @@ use Utopia\Logger\Adapter\Raygun;
use Utopia\Logger\Adapter\Sentry;
use Utopia\Logger\Log;
use Utopia\Logger\Logger;
use Utopia\Pools\Connection as PoolConnection;
use Utopia\Pools\Group;
use Utopia\Pools\Pool;
use Utopia\Queue;
@@ -1418,7 +1419,26 @@ App::setResource('console', function () {
]);
}, []);
App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform, Cache $cache, Document $project) {
App::setResource('connectionForProject', function (Group $pools, Document $project) {
if ($project->isEmpty() || $project->getId() === 'console') {
return $pools
->get('console')
->pop();
}
try {
$dsn = new DSN($project->getAttribute('database'));
} catch (\InvalidArgumentException) {
// TODO: Temporary until all projects are using shared tables
$dsn = new DSN('mysql://' . $project->getAttribute('database'));
}
return $pools
->get($dsn->getHost())
->pop();
}, ['pools', 'project']);
App::setResource('dbForProject', function (Group $pools, PoolConnection $connectionForProject, Database $dbForPlatform, Cache $cache, Document $project) {
if ($project->isEmpty() || $project->getId() === 'console') {
return $dbForPlatform;
}
@@ -1430,12 +1450,7 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform
$dsn = new DSN('mysql://' . $project->getAttribute('database'));
}
$dbAdapter = $pools
->get($dsn->getHost())
->pop()
->getResource();
$database = new Database($dbAdapter, $cache);
$database = new Database($connectionForProject->getResource(), $cache);
$database
->setMetadata('host', \gethostname())
@@ -1458,7 +1473,7 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform
}
return $database;
}, ['pools', 'dbForPlatform', 'cache', 'project']);
}, ['pools', 'connectionForProject', 'dbForPlatform', 'cache', 'project']);
App::setResource('dbForPlatform', function (Group $pools, Cache $cache) {
$dbAdapter = $pools