mirror of
https://github.com/appwrite/appwrite
synced 2026-05-19 06:58:21 +00:00
parent
7dfc654121
commit
0093ad7799
1 changed files with 36 additions and 53 deletions
|
|
@ -44,21 +44,17 @@ Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
|||
function getConsoleDB(Authorization $auth): Database
|
||||
{
|
||||
global $global;
|
||||
|
||||
/** @var \Utopia\Pools\Group $pools */
|
||||
$pools = $global->get('pools');
|
||||
|
||||
$pool = $pools['pools-console-main']['pool'];
|
||||
$dsn = $pools['pools-console-main']['dsn'];
|
||||
$connection = $pool->get();
|
||||
$dbAdapter = $pools
|
||||
->get('console')
|
||||
->pop()
|
||||
->getResource()
|
||||
;
|
||||
|
||||
$adapter = match ($dsn->getScheme()) {
|
||||
'mariadb' => new MariaDB($connection),
|
||||
'mysql' => new MySQL($connection),
|
||||
default => null
|
||||
};
|
||||
|
||||
$adapter->setDatabase($dsn->getPath());
|
||||
|
||||
$database = new Database($adapter, getCache());
|
||||
$database = new Database($dbAdapter, getCache());
|
||||
$database->setAuthorization($auth);
|
||||
|
||||
$database
|
||||
|
|
@ -71,29 +67,22 @@ function getConsoleDB(Authorization $auth): Database
|
|||
|
||||
function getProjectDB(Document $project, Authorization $auth): Database
|
||||
{
|
||||
global $global;
|
||||
|
||||
/** @var \Utopia\Pools\Group $pools */
|
||||
$pools = $global->get('pools');
|
||||
|
||||
if ($project->isEmpty() || $project->getId() === 'console') {
|
||||
return getConsoleDB($auth);
|
||||
}
|
||||
|
||||
global $global;
|
||||
$pools = $global->get('pools');
|
||||
$dbAdapter = $pools
|
||||
->get($project->getAttribute('database'))
|
||||
->pop()
|
||||
->getResource()
|
||||
;
|
||||
|
||||
$databaseName = $project->getAttribute('database');
|
||||
|
||||
$pool = $pools['pools-database-' . $databaseName]['pool'];
|
||||
$dsn = $pools['pools-database-' . $databaseName]['dsn'];
|
||||
|
||||
$connection = $pool->get();
|
||||
|
||||
$adapter = match ($dsn->getScheme()) {
|
||||
'mariadb' => new MariaDB($connection),
|
||||
'mysql' => new MySQL($connection),
|
||||
default => null
|
||||
};
|
||||
$adapter->setDatabase($dsn->getPath());
|
||||
|
||||
|
||||
$database = new Database($adapter, getCache());
|
||||
$database = new Database($dbAdapter, getCache());
|
||||
$database->setAuthorization($auth);
|
||||
|
||||
$database
|
||||
|
|
@ -106,23 +95,22 @@ function getProjectDB(Document $project, Authorization $auth): Database
|
|||
|
||||
function getCache(): Cache
|
||||
{
|
||||
return new Cache(new \Utopia\Cache\Adapter\None());
|
||||
// global $global;
|
||||
//
|
||||
// $pools = $global->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
//
|
||||
// $list = Config::getParam('pools-cache', []);
|
||||
// $adapters = [];
|
||||
//
|
||||
// foreach ($list as $value) {
|
||||
// $adapters[] = $pools
|
||||
// ->get($value)
|
||||
// ->pop()
|
||||
// ->getResource()
|
||||
// ;
|
||||
// }
|
||||
//
|
||||
// return new Cache(new Sharding($adapters));
|
||||
global $global;
|
||||
|
||||
$pools = $global->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
$list = Config::getParam('pools-cache', []);
|
||||
$adapters = [];
|
||||
|
||||
foreach ($list as $value) {
|
||||
$adapters[] = $pools
|
||||
->get($value)
|
||||
->pop()
|
||||
->getResource()
|
||||
;
|
||||
}
|
||||
|
||||
return new Cache(new Sharding($adapters));
|
||||
}
|
||||
|
||||
$realtime = new Realtime();
|
||||
|
|
@ -346,12 +334,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $global, $stats, $
|
|||
|
||||
$start = time();
|
||||
|
||||
$pools = $global->get('pools');
|
||||
$pool = $pools['pools-pubsub-main']['pool'];
|
||||
$dsn = $pools['pools-pubsub-main']['dsn'];
|
||||
$redis = new \Redis();
|
||||
$redis->connect($dsn->getHost(), $dsn->getPort());
|
||||
|
||||
$redis = $global->get('pools')->get('pubsub')->pop()->getResource(); /** @var Redis $redis */
|
||||
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
|
||||
|
||||
if ($redis->ping(true)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue