summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-12-18 22:23:53 +0100
committerGitHub <noreply@github.com>2017-12-18 22:23:53 +0100
commite294323df2852afb8615d99093b276e924333071 (patch)
treef1fef726c6f01c7b9149d0629dbb1dea390759f9 /core
parenta84d11de7bf9e26f2932e362435921556eb80560 (diff)
parent21489d5f24b4a63f6b579af59927310862abd884 (diff)
downloadnextcloud-server-e294323df2852afb8615d99093b276e924333071.tar.gz
nextcloud-server-e294323df2852afb8615d99093b276e924333071.zip
Merge pull request #7517 from nextcloud/add-index-to-share-table
Add index to share_with column in the share table
Diffstat (limited to 'core')
-rw-r--r--core/Command/Db/AddMissingIndices.php91
-rw-r--r--core/Migrations/Version13000Date20170718121200.php1
-rw-r--r--core/register_command.php1
3 files changed, 93 insertions, 0 deletions
diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php
new file mode 100644
index 00000000000..314bed8ccb1
--- /dev/null
+++ b/core/Command/Db/AddMissingIndices.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OC\Core\Command\Db;
+
+use OC\DB\SchemaWrapper;
+use OCP\IDBConnection;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class AddMissingIndices
+ *
+ * if you added any new indices to the database, this is the right place to add
+ * it your update routine for existing instances
+ *
+ * @package OC\Core\Command\Db
+ */
+class AddMissingIndices extends Command {
+
+ /** @var IDBConnection */
+ private $connection;
+
+ /**
+ * @param IDBConnection $connection
+ */
+ public function __construct(IDBConnection $connection) {
+ $this->connection = $connection;
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('db:add-missing-indices')
+ ->setDescription('Add missing indices to the database tables');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $this->addShareTableIndicies($output);
+
+ }
+
+ /**
+ * add missing indices to the share table
+ *
+ * @param OutputInterface $output
+ * @throws \Doctrine\DBAL\Schema\SchemaException
+ */
+ private function addShareTableIndicies(OutputInterface $output) {
+
+ $output->writeln('<info>Check indices of the share table.</info>');
+
+ $schema = new SchemaWrapper($this->connection);
+ $updated = false;
+
+ if ($schema->hasTable("share")) {
+ $table = $schema->getTable("share");
+ if (!$table->hasIndex('share_with_index')) {
+ $output->writeln('<info>Adding additional index to the share table, this can take some time...</info>');
+ $table->addIndex(['share_with'], 'share_with_index');
+ $this->connection->migrateToSchema($schema->getWrappedSchema());
+ $updated = true;
+ $output->writeln('<info>Share table updated successfully.</info>');
+ }
+ }
+
+ if (!$updated) {
+ $output->writeln('<info>Done.</info>');
+ }
+ }
+}
diff --git a/core/Migrations/Version13000Date20170718121200.php b/core/Migrations/Version13000Date20170718121200.php
index 0ab777f6de2..e71debfcb4b 100644
--- a/core/Migrations/Version13000Date20170718121200.php
+++ b/core/Migrations/Version13000Date20170718121200.php
@@ -400,6 +400,7 @@ class Version13000Date20170718121200 extends SimpleMigrationStep {
$table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
$table->addIndex(['file_source'], 'file_source_index');
$table->addIndex(['token'], 'token_index');
+ $table->addIndex(['share_with'], 'share_with_index');
}
if (!$schema->hasTable('jobs')) {
diff --git a/core/register_command.php b/core/register_command.php
index 60e151a5f2c..372d775dc14 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -90,6 +90,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger()));
$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection()));
+ $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection()));