diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 20b11986..fd678026 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -27,6 +27,7 @@ use OCA\Notifications\App; use OCA\Notifications\Capabilities; +use OCA\Notifications\Listener\AddMissingIndicesListener; use OCA\Notifications\Listener\BeforeTemplateRenderedListener; use OCA\Notifications\Listener\PostLoginListener; use OCA\Notifications\Listener\UserCreatedListener; @@ -37,6 +38,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\DB\Events\AddMissingIndicesEvent; use OCP\Notification\IManager; use OCP\User\Events\PostLoginEvent; use OCP\User\Events\UserCreatedEvent; @@ -56,6 +58,7 @@ public function register(IRegistrationContext $context): void { $context->registerNotifierService(AdminNotifications::class); + $context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class); $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); $context->registerEventListener(UserCreatedEvent::class, UserCreatedListener::class); diff --git a/lib/Listener/AddMissingIndicesListener.php b/lib/Listener/AddMissingIndicesListener.php new file mode 100644 index 00000000..e811ec91 --- /dev/null +++ b/lib/Listener/AddMissingIndicesListener.php @@ -0,0 +1,49 @@ + + * + * @author Joas Schilling + * + * @license AGPL-3.0-or-later + * + * 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 OCA\Notifications\Listener; + +use OCP\DB\Events\AddMissingIndicesEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +/** + * @template-implements IEventListener + */ +class AddMissingIndicesListener implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof AddMissingIndicesEvent)) { + // Unrelated + return; + } + + $event->addMissingIndex( + 'notifications_pushhash', + 'oc_npushhash_di', + ['deviceidentifier'], + ); + } +} diff --git a/lib/Migration/Version2010Date20210218082811.php b/lib/Migration/Version2010Date20210218082811.php index 6708653a..254490bf 100644 --- a/lib/Migration/Version2010Date20210218082811.php +++ b/lib/Migration/Version2010Date20210218082811.php @@ -98,6 +98,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]); $table->setPrimaryKey(['id']); $table->addUniqueIndex(['uid', 'token'], 'oc_npushhash_uid'); + $table->addIndex(['deviceidentifier'], 'oc_npushhash_di'); } return $schema; }