@@ -91,6 +91,7 @@ class Connection extends PrimaryReadReplicaConnection {
9191 protected array $ shards = [];
9292 protected ShardConnectionManager $ shardConnectionManager ;
9393 protected AutoIncrementHandler $ autoIncrementHandler ;
94+ protected bool $ isShardingEnabled ;
9495
9596 public const SHARD_PRESETS = [
9697 'filecache ' => [
@@ -130,14 +131,17 @@ public function __construct(
130131 parent ::__construct ($ params , $ driver , $ config , $ eventManager );
131132 $ this ->adapter = new $ params ['adapter ' ]($ this );
132133 $ this ->tablePrefix = $ params ['tablePrefix ' ];
133-
134- /** @psalm-suppress InvalidArrayOffset */
135- $ this ->shardConnectionManager = $ this ->params ['shard_connection_manager ' ] ?? Server::get (ShardConnectionManager::class);
136- /** @psalm-suppress InvalidArrayOffset */
137- $ this ->autoIncrementHandler = $ this ->params ['auto_increment_handler ' ] ?? new AutoIncrementHandler (
138- Server::get (ICacheFactory::class),
139- $ this ->shardConnectionManager ,
140- );
134+ $ this ->isShardingEnabled = isset ($ this ->params ['dbsharding ' ]) && !empty ($ this ->params ['dbsharding ' ]);
135+
136+ if ($ this ->isShardingEnabled ) {
137+ /** @psalm-suppress InvalidArrayOffset */
138+ $ this ->shardConnectionManager = $ this ->params ['shard_connection_manager ' ] ?? Server::get (ShardConnectionManager::class);
139+ /** @psalm-suppress InvalidArrayOffset */
140+ $ this ->autoIncrementHandler = $ this ->params ['auto_increment_handler ' ] ?? new AutoIncrementHandler (
141+ Server::get (ICacheFactory::class),
142+ $ this ->shardConnectionManager ,
143+ );
144+ }
141145 $ this ->systemConfig = \OC ::$ server ->getSystemConfig ();
142146 $ this ->clock = Server::get (ClockInterface::class);
143147 $ this ->logger = Server::get (LoggerInterface::class);
@@ -157,7 +161,7 @@ public function __construct(
157161 }
158162
159163 /** @var array<string, array{shards: array[], mapper: ?string}> $shardConfig */
160- $ shardConfig = $ this ->params ['sharding ' ] ?? [];
164+ $ shardConfig = $ this ->params ['dbsharding ' ] ?? [];
161165 $ shardNames = array_keys ($ shardConfig );
162166 $ this ->shards = array_map (function (array $ config , string $ name ) {
163167 if (!isset (self ::SHARD_PRESETS [$ name ])) {
@@ -192,10 +196,12 @@ public function __construct(
192196 */
193197 public function getShardConnections (): array {
194198 $ connections = [];
195- foreach ($ this ->shards as $ shardDefinition ) {
196- foreach ($ shardDefinition ->getAllShards () as $ shard ) {
197- /** @var ConnectionAdapter $connection */
198- $ connections [] = $ this ->shardConnectionManager ->getConnection ($ shardDefinition , $ shard );
199+ if ($ this ->isShardingEnabled ) {
200+ foreach ($ this ->shards as $ shardDefinition ) {
201+ foreach ($ shardDefinition ->getAllShards () as $ shard ) {
202+ /** @var ConnectionAdapter $connection */
203+ $ connections [] = $ this ->shardConnectionManager ->getConnection ($ shardDefinition , $ shard );
204+ }
199205 }
200206 }
201207 return $ connections ;
@@ -255,7 +261,7 @@ public function getQueryBuilder(): IQueryBuilder {
255261 $ this ->systemConfig ,
256262 $ this ->logger
257263 );
258- if (count ($ this ->partitions ) > 0 ) {
264+ if ($ this -> isShardingEnabled && count ($ this ->partitions ) > 0 ) {
259265 $ builder = new PartitionedQueryBuilder (
260266 $ builder ,
261267 $ this ->shards ,
0 commit comments