remove unnecessary db instances
This commit is contained in:
parent
ba8fef944c
commit
ee0c9e5b81
|
@ -52,7 +52,13 @@ class Server
|
||||||
* Container scoped Database connection.
|
* Container scoped Database connection.
|
||||||
* @var Database
|
* @var Database
|
||||||
*/
|
*/
|
||||||
public Database $db;
|
public Database $consoleDb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Container scoped Database connection.
|
||||||
|
* @var Database
|
||||||
|
*/
|
||||||
|
public Database $projectDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container scoped Redis connection.
|
* Container scoped Redis connection.
|
||||||
|
@ -85,10 +91,14 @@ class Server
|
||||||
$this->usage->column('messages', Table::TYPE_INT);
|
$this->usage->column('messages', Table::TYPE_INT);
|
||||||
$this->usage->create();
|
$this->usage->create();
|
||||||
|
|
||||||
$this->db = new Database();
|
$this->consoleDb = new Database();
|
||||||
$this->db->setAdapter(new RedisAdapter(new MySQLAdapter($this->register), $this->register));
|
$this->consoleDb->setAdapter(new RedisAdapter(new MySQLAdapter($this->register), $this->register));
|
||||||
$this->db->setNamespace('app_console');
|
$this->consoleDb->setNamespace('app_console');
|
||||||
$this->db->setMocks(Config::getParam('collections', []));
|
$this->consoleDb->setMocks(Config::getParam('collections', []));
|
||||||
|
|
||||||
|
$this->projectDb = new Database();
|
||||||
|
$this->projectDb->setAdapter(new RedisAdapter(new MySQLAdapter($this->register), $this->register));
|
||||||
|
$this->projectDb->setMocks(Config::getParam('collections', []));
|
||||||
|
|
||||||
$this->server = new SwooleServer($host, $port, SWOOLE_PROCESS);
|
$this->server = new SwooleServer($host, $port, SWOOLE_PROCESS);
|
||||||
$this->server->set($config);
|
$this->server->set($config);
|
||||||
|
@ -125,7 +135,7 @@ class Server
|
||||||
'data' => '{}'
|
'data' => '{}'
|
||||||
];
|
];
|
||||||
Authorization::disable();
|
Authorization::disable();
|
||||||
$document = $this->db->createDocument($document);
|
$document = $this->consoleDb->createDocument($document);
|
||||||
Authorization::enable();
|
Authorization::enable();
|
||||||
$this->server->document_id = $document->getId();
|
$this->server->document_id = $document->getId();
|
||||||
});
|
});
|
||||||
|
@ -189,7 +199,7 @@ class Server
|
||||||
'data' => json_encode($payload)
|
'data' => json_encode($payload)
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$document = $this->db->updateDocument($document);
|
$document = $this->consoleDb->updateDocument($document);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::error('[Error] Type: '.get_class($th));
|
Console::error('[Error] Type: '.get_class($th));
|
||||||
Console::error('[Error] Message: '.$th->getMessage());
|
Console::error('[Error] Message: '.$th->getMessage());
|
||||||
|
@ -485,7 +495,7 @@ class Server
|
||||||
&& array_key_exists('project', $this->subscriptions['console']['role:member'])
|
&& array_key_exists('project', $this->subscriptions['console']['role:member'])
|
||||||
) {
|
) {
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$list = $this->db->getCollection([
|
$list = $this->consoleDb->getCollection([
|
||||||
'filters' => [
|
'filters' => [
|
||||||
'$collection='.Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
|
'$collection='.Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
|
||||||
'timestamp>'.(time() - 15)
|
'timestamp>'.(time() - 15)
|
||||||
|
@ -528,26 +538,9 @@ class Server
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$this->projectDb->setNamespace('app_'.$project);
|
||||||
* This is redundant soon and will be gone with merging the usage branch.
|
|
||||||
*/
|
|
||||||
$db = $this->register->get('dbPool')->get();
|
|
||||||
$redis = $this->register->get('redisPool')->get();
|
|
||||||
|
|
||||||
$this->register->set('db', function () use (&$db) {
|
$user = $this->projectDb->getDocument($userId);
|
||||||
return $db;
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->register->set('cache', function () use (&$redis) {
|
|
||||||
return $redis;
|
|
||||||
});
|
|
||||||
|
|
||||||
$projectDB = new Database();
|
|
||||||
$projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($this->register), $this->register));
|
|
||||||
$projectDB->setNamespace('app_'.$project);
|
|
||||||
$projectDB->setMocks(Config::getParam('collections', []));
|
|
||||||
|
|
||||||
$user = $projectDB->getDocument($userId);
|
|
||||||
|
|
||||||
Parser::setUser($user);
|
Parser::setUser($user);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue