Skip to content

Commit

Permalink
Add twofactor_providers_uid index
Browse files Browse the repository at this point in the history
Fixes nextcloud#12943

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Dec 21, 2018
1 parent c2d75dd commit 16cc68a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ function(GenericEvent $event) use ($container) {
$subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
}
}

if ($schema->hasTable('twofactor_providers')) {
$table = $schema->getTable('twofactor_providers');

if (!$table->hasIndex('twofactor_providers_uid')) {
$subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
}
}
}
);
}
Expand Down
17 changes: 15 additions & 2 deletions core/Command/Db/AddMissingIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function configure() {
}

protected function execute(InputInterface $input, OutputInterface $output) {
$this->addShareTableIndicies($output);
$this->addCoreIndexes($output);

// Dispatch event so apps can also update indexes if needed
$event = new GenericEvent($output);
Expand All @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
* @param OutputInterface $output
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
private function addShareTableIndicies(OutputInterface $output) {
private function addCoreIndexes(OutputInterface $output) {

$output->writeln('<info>Check indices of the share table.</info>');

Expand Down Expand Up @@ -116,6 +116,7 @@ private function addShareTableIndicies(OutputInterface $output) {
}
}

$output->writeln('<info>Check indices of the filecache table.</info>');
if ($schema->hasTable('filecache')) {
$table = $schema->getTable('filecache');
if (!$table->hasIndex('fs_mtime')) {
Expand All @@ -127,6 +128,18 @@ private function addShareTableIndicies(OutputInterface $output) {
}
}

$output->writeln('<info>Check indices of the twofactor_providers table.</info>');
if ($schema->hasTable('twofactor_providers')) {
$table = $schema->getTable('twofactor_providers');
if (!$table->hasIndex('twofactor_providers_uid')) {
$output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>');
$table->addIndex(['uid'], 'twofactor_providers_uid');
$this->connection->migrateToSchema($schema->getWrappedSchema());
$updated = true;
$output->writeln('<info>Twofactor_providers table updated successfully.</info>');
}
}

if (!$updated) {
$output->writeln('<info>Done.</info>');
}
Expand Down
1 change: 1 addition & 0 deletions core/Migrations/Version14000Date20180522074438.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure,
'length' => 1,
]);
$table->setPrimaryKey(['provider_id', 'uid']);
$table->addIndex(['uid'], 'twofactor_providers_uid');
}

return $schema;
Expand Down

0 comments on commit 16cc68a

Please sign in to comment.