From 0093ad7799fe2ddc341f4fe68fbce0c52cd75f4d Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 4 Jun 2024 11:57:16 -0400 Subject: [PATCH] Revert "wip: Starting realtime" This reverts commit 7dfc6541218b91f7430785075134028f47efd609. --- app/realtime.php | 89 ++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 53 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index ae34e768b4..2e2024216a 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -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)) {