From 792560b02b0df997513e5d8a1d8bb316355c61fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 Feb 2024 13:38:54 +0100 Subject: [PATCH] perf(sharing): Add a better index to select shares as they always have type+with Signed-off-by: Joas Schilling --- core/Application.php | 12 +++- .../Version13000Date20170718121200.php | 4 +- .../Version29000Date20240209123412.php | 56 +++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 core/Migrations/Version29000Date20240209123412.php diff --git a/core/Application.php b/core/Application.php index 700fb3297af..f9a16ca1cde 100644 --- a/core/Application.php +++ b/core/Application.php @@ -79,10 +79,18 @@ class Application extends App { $notificationManager->registerNotifierService(AuthenticationNotifier::class); $eventDispatcher->addListener(AddMissingIndicesEvent::class, function (AddMissingIndicesEvent $event) { + /** + * Replaced by the share_type_with index below + * $event->addMissingIndex( + * 'share', + * 'share_with_index', + * ['share_with'] + * ); + */ $event->addMissingIndex( 'share', - 'share_with_index', - ['share_with'] + 'share_type_with', + ['share_type', 'share_with'] ); $event->addMissingIndex( 'share', diff --git a/core/Migrations/Version13000Date20170718121200.php b/core/Migrations/Version13000Date20170718121200.php index da83b0732d8..63cdd1d6a34 100644 --- a/core/Migrations/Version13000Date20170718121200.php +++ b/core/Migrations/Version13000Date20170718121200.php @@ -475,7 +475,9 @@ 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'); + // Replaced by the share_type_with index below + // $table->addIndex(['share_with'], 'share_with_index'); + $table->addIndex(['share_type', 'share_with'], 'share_type_with'); $table->addIndex(['parent'], 'parent_index'); $table->addIndex(['uid_owner'], 'owner_index'); $table->addIndex(['uid_initiator'], 'initiator_index'); diff --git a/core/Migrations/Version29000Date20240209123412.php b/core/Migrations/Version29000Date20240209123412.php new file mode 100644 index 00000000000..fa35210f597 --- /dev/null +++ b/core/Migrations/Version29000Date20240209123412.php @@ -0,0 +1,56 @@ + + * + * @author Your name + * + * @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\Migrations; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +/** + * Auto-generated migration step: Please modify to your needs! + */ +class Version29000Date20240209123412 extends SimpleMigrationStep { + /** + * @param IOutput $output + * @param Closure(): ISchemaWrapper $schemaClosure + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('share'); + if ($table->hasIndex('share_with_index')) { + $table->dropIndex('share_with_index'); + return $schema; + } + return null; + } + +}