From fda98ee917508836e42cc211cdfc9f652a2622c1 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 14 Dec 2017 16:37:11 +0100 Subject: [PATCH 1/4] add occ command to add a index to share_with at the share table Signed-off-by: Bjoern Schiessle --- core/Command/Db/AddIndexToShareTable.php | 73 ++++++++++++++++++++++++ core/register_command.php | 1 + 2 files changed, 74 insertions(+) create mode 100644 core/Command/Db/AddIndexToShareTable.php diff --git a/core/Command/Db/AddIndexToShareTable.php b/core/Command/Db/AddIndexToShareTable.php new file mode 100644 index 0000000000..cfd5c1871b --- /dev/null +++ b/core/Command/Db/AddIndexToShareTable.php @@ -0,0 +1,73 @@ + + * + * @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 . + * + */ + + +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 AddIndexToShareTable 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-index-to-share-table') + ->setDescription('Add a index to share_with at the share table to increase performance'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + + $schema = new SchemaWrapper($this->connection); + $updated = false; + + if ($schema->hasTable("share")) { + $table = $schema->getTable("share"); + if (!$table->hasIndex('share_with_index')) { + $output->writeln('Adding additional index to the share table, this can take some time...'); + $table->addIndex(['share_with'], 'share_with_index'); + $this->connection->migrateToSchema($schema->getWrappedSchema()); + $updated = true; + $output->writeln('Share table updated successfully.'); + } + } + + if (!$updated) { + $output->writeln('All index already existed, nothing to do.'); + } + + return 0; + + } +} diff --git a/core/register_command.php b/core/register_command.php index 60e151a5f2..e7c33351a7 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\AddIndexToShareTable(\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())); From de9858142141f3fdc80ed443e59ef9ef11fce02c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 14 Dec 2017 16:42:43 +0100 Subject: [PATCH 2/4] add index for share_with table for newly created tables Signed-off-by: Bjoern Schiessle --- core/Migrations/Version13000Date20170718121200.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/Migrations/Version13000Date20170718121200.php b/core/Migrations/Version13000Date20170718121200.php index 0ab777f6de..e71debfcb4 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')) { From 41ee23a0543bac873b03f1a8e45178f9ec0a4075 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 15 Dec 2017 10:45:00 +0100 Subject: [PATCH 3/4] make occ command more generic Signed-off-by: Bjoern Schiessle --- ...ToShareTable.php => AddMissingIndices.php} | 32 +++++++++++++++---- core/register_command.php | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) rename core/Command/Db/{AddIndexToShareTable.php => AddMissingIndices.php} (73%) diff --git a/core/Command/Db/AddIndexToShareTable.php b/core/Command/Db/AddMissingIndices.php similarity index 73% rename from core/Command/Db/AddIndexToShareTable.php rename to core/Command/Db/AddMissingIndices.php index cfd5c1871b..314bed8ccb 100644 --- a/core/Command/Db/AddIndexToShareTable.php +++ b/core/Command/Db/AddMissingIndices.php @@ -28,7 +28,15 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class AddIndexToShareTable extends Command { +/** + * 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; @@ -43,11 +51,24 @@ class AddIndexToShareTable extends Command { protected function configure() { $this - ->setName('db:add-index-to-share-table') - ->setDescription('Add a index to share_with at the share table to increase performance'); + ->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('Check indices of the share table.'); $schema = new SchemaWrapper($this->connection); $updated = false; @@ -64,10 +85,7 @@ class AddIndexToShareTable extends Command { } if (!$updated) { - $output->writeln('All index already existed, nothing to do.'); + $output->writeln('Done.'); } - - return 0; - } } diff --git a/core/register_command.php b/core/register_command.php index e7c33351a7..372d775dc1 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -90,7 +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\AddIndexToShareTable(\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())); From 21489d5f24b4a63f6b579af59927310862abd884 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 15 Dec 2017 12:03:42 +0100 Subject: [PATCH 4/4] update autoloader Signed-off-by: Bjoern Schiessle Signed-off-by: Roeland Jago Douma --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index a3b8534927..738054cd37 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -459,6 +459,7 @@ return array( 'OC\\Core\\Command\\Config\\System\\DeleteConfig' => $baseDir . '/core/Command/Config/System/DeleteConfig.php', 'OC\\Core\\Command\\Config\\System\\GetConfig' => $baseDir . '/core/Command/Config/System/GetConfig.php', 'OC\\Core\\Command\\Config\\System\\SetConfig' => $baseDir . '/core/Command/Config/System/SetConfig.php', + 'OC\\Core\\Command\\Db\\AddMissingIndices' => $baseDir . '/core/Command/Db/AddMissingIndices.php', 'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => $baseDir . '/core/Command/Db/ConvertFilecacheBigInt.php', 'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => $baseDir . '/core/Command/Db/ConvertMysqlToMB4.php', 'OC\\Core\\Command\\Db\\ConvertType' => $baseDir . '/core/Command/Db/ConvertType.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 408a30e254..7ffbd4c788 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -489,6 +489,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Command\\Config\\System\\DeleteConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/DeleteConfig.php', 'OC\\Core\\Command\\Config\\System\\GetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/GetConfig.php', 'OC\\Core\\Command\\Config\\System\\SetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/SetConfig.php', + 'OC\\Core\\Command\\Db\\AddMissingIndices' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingIndices.php', 'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertFilecacheBigInt.php', 'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertMysqlToMB4.php', 'OC\\Core\\Command\\Db\\ConvertType' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertType.php',