fix(db): Prevent two connections for single node databases

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Christoph Wurst 1 month ago
parent c0b54c7577
commit ffee499f01
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8

@ -58,6 +58,7 @@ use OCP\Profiler\IProfiler;
use OCP\Server; use OCP\Server;
use Psr\Clock\ClockInterface; use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use function count;
use function in_array; use function in_array;
class Connection extends PrimaryReadReplicaConnection { class Connection extends PrimaryReadReplicaConnection {
@ -100,7 +101,7 @@ class Connection extends PrimaryReadReplicaConnection {
* @throws \Exception * @throws \Exception
*/ */
public function __construct( public function __construct(
array $params, private array $params,
Driver $driver, Driver $driver,
?Configuration $config = null, ?Configuration $config = null,
?EventManager $eventManager = null ?EventManager $eventManager = null
@ -163,6 +164,15 @@ class Connection extends PrimaryReadReplicaConnection {
} }
} }
protected function performConnect(?string $connectionName = null): bool {
if (($connectionName ?? 'replica') === 'replica'
&& count($this->params['replica']) === 1
&& $this->params['primary'] === $this->params['replica'][0]) {
return parent::performConnect('primary');
}
return parent::performConnect($connectionName);
}
public function getStats(): array { public function getStats(): array {
return [ return [
'built' => $this->queriesBuilt, 'built' => $this->queriesBuilt,

Loading…
Cancel
Save