aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB/Connection.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-06-13 18:34:35 +0200
committerLouis Chemineau <louis@chmn.me>2024-08-28 10:18:53 +0200
commitf5b348674449d023367b5e5f84cb4ac1de98605b (patch)
tree796923a4dea47f2aeba6eb4b74caa44a2b562725 /lib/private/DB/Connection.php
parentc58bdbf378a6c2abc6b9f33dae175de762f33d8a (diff)
downloadnextcloud-server-f5b348674449d023367b5e5f84cb4ac1de98605b.tar.gz
nextcloud-server-f5b348674449d023367b5e5f84cb4ac1de98605b.zip
feat: add option to automatically partition queries by specific tables
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/DB/Connection.php')
-rw-r--r--lib/private/DB/Connection.php19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 9aeba16fb24..74cdba3e218 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -23,6 +23,8 @@ use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Statement;
+use OC\DB\QueryBuilder\Partitioned\PartitionSplit;
+use OC\DB\QueryBuilder\Partitioned\PartitionedQueryBuilder;
use OC\DB\QueryBuilder\QueryBuilder;
use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -76,6 +78,9 @@ class Connection extends PrimaryReadReplicaConnection {
protected bool $logRequestId;
protected string $requestId;
+ /** @var array<string, list<string>> */
+ protected array $partitions;
+
/**
* Initializes a new instance of the Connection class.
*
@@ -118,6 +123,8 @@ class Connection extends PrimaryReadReplicaConnection {
$this->_config->setSQLLogger($debugStack);
}
+ $this->partitions = $this->systemConfig->getValue('db.partitions', []);
+
$this->setNestTransactionsWithSavepoints(true);
}
@@ -169,11 +176,21 @@ class Connection extends PrimaryReadReplicaConnection {
*/
public function getQueryBuilder(): IQueryBuilder {
$this->queriesBuilt++;
- return new QueryBuilder(
+ $builder = new QueryBuilder(
new ConnectionAdapter($this),
$this->systemConfig,
$this->logger
);
+ if (count($this->partitions) > 0) {
+ $builder = new PartitionedQueryBuilder($builder);
+ foreach ($this->partitions as $name => $tables) {
+ $partition = new PartitionSplit($name, $tables);
+ $builder->addPartition($partition);
+ }
+ return $builder;
+ } else {
+ return $builder;
+ }
}
/**