aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2024-04-24 11:41:30 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2024-05-28 10:38:36 +0200
commit3bfba2042c0397452193e9b6f1fa4bd1596b17a6 (patch)
tree60a1cb4b7f8ca8540738f0178898319c1c887cd7 /lib
parentf0ec5489a444ced8d8794b93abf42a3de973cf54 (diff)
downloadnextcloud-server-3bfba2042c0397452193e9b6f1fa4bd1596b17a6.tar.gz
nextcloud-server-3bfba2042c0397452193e9b6f1fa4bd1596b17a6.zip
fix(db): Prevent two connections for single node databases
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/Connection.php12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index b748312d156..8d300123a40 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -31,6 +31,7 @@ use OCP\Profiler\IProfiler;
use OCP\Server;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;
+use function count;
use function in_array;
class Connection extends PrimaryReadReplicaConnection {
@@ -73,7 +74,7 @@ class Connection extends PrimaryReadReplicaConnection {
* @throws \Exception
*/
public function __construct(
- array $params,
+ private array $params,
Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
@@ -138,6 +139,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 {
return [
'built' => $this->queriesBuilt,