mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Cache database factory adapters
This commit is contained in:
@@ -16,6 +16,11 @@ use Utopia\System\System;
|
||||
|
||||
class DatabaseFactory
|
||||
{
|
||||
/**
|
||||
* @var array<string, DatabasePool>
|
||||
*/
|
||||
protected array $adapters = [];
|
||||
|
||||
public function __construct(
|
||||
protected Group $pools,
|
||||
protected Cache $cache,
|
||||
@@ -30,7 +35,7 @@ class DatabaseFactory
|
||||
int $maxQueryValues = 0,
|
||||
array $metadata = [],
|
||||
): Database {
|
||||
$database = $this->newDatabase(new DatabasePool($this->pools->get('console')));
|
||||
$database = $this->newDatabase($this->adapter('console'));
|
||||
|
||||
$database
|
||||
->setDatabase($this->database)
|
||||
@@ -51,7 +56,7 @@ class DatabaseFactory
|
||||
): Database {
|
||||
$dsn = $this->dsn($project->getAttribute('database'));
|
||||
$database = $this->newDatabase(
|
||||
new DatabasePool($this->pools->get($dsn->getHost())),
|
||||
$this->adapter($dsn->getHost()),
|
||||
$this->destinationFor($dsn)
|
||||
);
|
||||
|
||||
@@ -75,7 +80,7 @@ class DatabaseFactory
|
||||
$collections = Config::getParam('collections', []);
|
||||
$logsCollections = \array_keys($collections['logs'] ?? []);
|
||||
|
||||
$database = $this->newDatabase(new DatabasePool($this->pools->get('logs')));
|
||||
$database = $this->newDatabase($this->adapter('logs'));
|
||||
|
||||
$database
|
||||
->setDatabase($this->database)
|
||||
@@ -105,7 +110,7 @@ class DatabaseFactory
|
||||
$projectDsn = $this->dsn($project->getAttribute('database'));
|
||||
$databaseType = $databaseDocument->getAttribute('type', '');
|
||||
|
||||
$database = $this->newDatabase(new DatabasePool($this->pools->get($databaseDsn->getHost())));
|
||||
$database = $this->newDatabase($this->adapter($databaseDsn->getHost()));
|
||||
|
||||
$database
|
||||
->setDatabase($this->database)
|
||||
@@ -163,6 +168,11 @@ class DatabaseFactory
|
||||
return new Database($adapter, $this->cache);
|
||||
}
|
||||
|
||||
protected function adapter(string $name): DatabasePool
|
||||
{
|
||||
return $this->adapters[$name] ??= new DatabasePool($this->pools->get($name));
|
||||
}
|
||||
|
||||
protected function configureDocumentTypes(Database $database): Database
|
||||
{
|
||||
return $database->setDocumentType('users', User::class);
|
||||
|
||||
Reference in New Issue
Block a user