diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-04-21 09:59:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-21 09:59:04 +0200 |
commit | f4135c72f505f13891e0b05e7e4f4d2d921462b0 (patch) | |
tree | d242ace298b2829c7eaa05430c05ee8c8f3f676d | |
parent | 12ed5c9ff3e9dac25b43a1ad934a97a86037000b (diff) | |
parent | 7fbd93b2ad66a1ca83ef2a2778128bf2cda06caf (diff) | |
download | nextcloud-server-f4135c72f505f13891e0b05e7e4f4d2d921462b0.tar.gz nextcloud-server-f4135c72f505f13891e0b05e7e4f4d2d921462b0.zip |
Merge pull request #31047 from nextcloud/enh/preferences-index
Additional index on oc_preferences to make queries without a user filter faster
-rw-r--r-- | core/Application.php | 7 | ||||
-rw-r--r-- | core/Command/Db/AddMissingIndices.php | 13 | ||||
-rw-r--r-- | core/Migrations/Version13000Date20170718121200.php | 1 | ||||
-rw-r--r-- | lib/private/AllConfig.php | 4 |
4 files changed, 25 insertions, 0 deletions
diff --git a/core/Application.php b/core/Application.php index 34932cab183..443585ebc79 100644 --- a/core/Application.php +++ b/core/Application.php @@ -218,6 +218,13 @@ class Application extends App { $subject->addHintForMissingSubject($table->getName(), 'direct_edit_timestamp'); } } + + if ($schema->hasTable('preferences')) { + $table = $schema->getTable('preferences'); + if (!$table->hasIndex('preferences_app_key')) { + $subject->addHintForMissingSubject($table->getName(), 'preferences_app_key'); + } + } } ); diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php index a4379ffacc3..8394e75e845 100644 --- a/core/Command/Db/AddMissingIndices.php +++ b/core/Command/Db/AddMissingIndices.php @@ -435,6 +435,19 @@ class AddMissingIndices extends Command { } } + $output->writeln('<info>Check indices of the oc_preferences table.</info>'); + if ($schema->hasTable('preferences')) { + $table = $schema->getTable('preferences'); + if (!$table->hasIndex('preferences_app_key')) { + $output->writeln('<info>Adding preferences_app_key index to the oc_preferences table, this can take some time...</info>'); + + $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $updated = true; + $output->writeln('<info>oc_properties table updated successfully.</info>'); + } + } + if (!$updated) { $output->writeln('<info>Done.</info>'); } diff --git a/core/Migrations/Version13000Date20170718121200.php b/core/Migrations/Version13000Date20170718121200.php index 02864830b2c..3e14b4af47a 100644 --- a/core/Migrations/Version13000Date20170718121200.php +++ b/core/Migrations/Version13000Date20170718121200.php @@ -333,6 +333,7 @@ class Version13000Date20170718121200 extends SimpleMigrationStep { 'notnull' => false, ]); $table->setPrimaryKey(['userid', 'appid', 'configkey']); + $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); } if (!$schema->hasTable('properties')) { diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 36eb0bbf6d9..e5a6e6a5acd 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -497,6 +497,8 @@ class AllConfig implements \OCP\IConfig { $sql .= 'AND `configvalue` = ?'; } + $sql .= ' ORDER BY `userid`'; + $result = $this->connection->executeQuery($sql, [$appName, $key, $value]); $userIDs = []; @@ -534,6 +536,8 @@ class AllConfig implements \OCP\IConfig { $sql .= 'AND LOWER(`configvalue`) = ?'; } + $sql .= ' ORDER BY `userid`'; + $result = $this->connection->executeQuery($sql, [$appName, $key, strtolower($value)]); $userIDs = []; |