瀏覽代碼

Merge pull request #33405 from nextcloud/perf/new-index-mounts-class

Julius Härtl 2 年之前
父節點
當前提交
e750137a9a
共有 3 個文件被更改,包括 21 次插入0 次删除
  1. 7 0
      core/Application.php
  2. 13 0
      core/Command/Db/AddMissingIndices.php
  3. 1 0
      core/Migrations/Version24000Date20220202150027.php

+ 7 - 0
core/Application.php

@@ -225,6 +225,13 @@ class Application extends App {
 						$subject->addHintForMissingSubject($table->getName(), 'preferences_app_key');
 					}
 				}
+
+				if ($schema->hasTable('mounts')) {
+					$table = $schema->getTable('mounts');
+					if (!$table->hasIndex('mounts_class_index')) {
+						$subject->addHintForMissingSubject($table->getName(), 'mounts_class_index');
+					}
+				}
 			}
 		);
 

+ 13 - 0
core/Command/Db/AddMissingIndices.php

@@ -444,6 +444,19 @@ class AddMissingIndices extends Command {
 			}
 		}
 
+		$output->writeln('<info>Check indices of the oc_mounts table.</info>');
+		if ($schema->hasTable('mounts')) {
+			$table = $schema->getTable('mounts');
+			if (!$table->hasIndex('mounts_class_index')) {
+				$output->writeln('<info>Adding mounts_class_index index to the oc_mounts table, this can take some time...</info>');
+
+				$table->addIndex(['mount_provider_class'], 'mounts_class_index');
+				$this->connection->migrateToSchema($schema->getWrappedSchema());
+				$updated = true;
+				$output->writeln('<info>oc_mounts table updated successfully.</info>');
+			}
+		}
+
 		if (!$updated) {
 			$output->writeln('<info>Done.</info>');
 		}

+ 1 - 0
core/Migrations/Version24000Date20220202150027.php

@@ -30,6 +30,7 @@ class Version24000Date20220202150027 extends SimpleMigrationStep {
 				'notnull' => false,
 				'length' => 128,
 			]);
+			$table->addIndex(['mount_provider_class'], 'mounts_class_index');
 			return $schema;
 		}
 		return null;