Revert "wip: Starting realtime"

This reverts commit 7dfc654121.
This commit is contained in:
Binyamin Yawitz 2024-06-04 11:57:16 -04:00
parent 7dfc654121
commit 0093ad7799
No known key found for this signature in database

View file

@ -44,21 +44,17 @@ Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
function getConsoleDB(Authorization $auth): Database function getConsoleDB(Authorization $auth): Database
{ {
global $global; global $global;
/** @var \Utopia\Pools\Group $pools */
$pools = $global->get('pools'); $pools = $global->get('pools');
$pool = $pools['pools-console-main']['pool']; $dbAdapter = $pools
$dsn = $pools['pools-console-main']['dsn']; ->get('console')
$connection = $pool->get(); ->pop()
->getResource()
;
$adapter = match ($dsn->getScheme()) { $database = new Database($dbAdapter, getCache());
'mariadb' => new MariaDB($connection),
'mysql' => new MySQL($connection),
default => null
};
$adapter->setDatabase($dsn->getPath());
$database = new Database($adapter, getCache());
$database->setAuthorization($auth); $database->setAuthorization($auth);
$database $database
@ -71,29 +67,22 @@ function getConsoleDB(Authorization $auth): Database
function getProjectDB(Document $project, 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') { if ($project->isEmpty() || $project->getId() === 'console') {
return getConsoleDB($auth); return getConsoleDB($auth);
} }
global $global; $dbAdapter = $pools
$pools = $global->get('pools'); ->get($project->getAttribute('database'))
->pop()
->getResource()
;
$databaseName = $project->getAttribute('database'); $database = new Database($dbAdapter, getCache());
$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->setAuthorization($auth); $database->setAuthorization($auth);
$database $database
@ -106,23 +95,22 @@ function getProjectDB(Document $project, Authorization $auth): Database
function getCache(): Cache function getCache(): Cache
{ {
return new Cache(new \Utopia\Cache\Adapter\None()); global $global;
// global $global;
// $pools = $global->get('pools'); /** @var \Utopia\Pools\Group $pools */
// $pools = $global->get('pools'); /** @var \Utopia\Pools\Group $pools */
// $list = Config::getParam('pools-cache', []);
// $list = Config::getParam('pools-cache', []); $adapters = [];
// $adapters = [];
// foreach ($list as $value) {
// foreach ($list as $value) { $adapters[] = $pools
// $adapters[] = $pools ->get($value)
// ->get($value) ->pop()
// ->pop() ->getResource()
// ->getResource() ;
// ; }
// }
// return new Cache(new Sharding($adapters));
// return new Cache(new Sharding($adapters));
} }
$realtime = new Realtime(); $realtime = new Realtime();
@ -346,12 +334,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $global, $stats, $
$start = time(); $start = time();
$pools = $global->get('pools'); $redis = $global->get('pools')->get('pubsub')->pop()->getResource(); /** @var Redis $redis */
$pool = $pools['pools-pubsub-main']['pool'];
$dsn = $pools['pools-pubsub-main']['dsn'];
$redis = new \Redis();
$redis->connect($dsn->getHost(), $dsn->getPort());
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1); $redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
if ($redis->ping(true)) { if ($redis->ping(true)) {