Skip to content

Commit

Permalink
Merge pull request #1806 from nextcloud/feat/noid/add-missing-indices
Browse files Browse the repository at this point in the history
feat(db): Add index on device identifier for quicker deletion
  • Loading branch information
nickvergessen authored Feb 22, 2024
2 parents 22239e5 + fcd160b commit a41fc4f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
49 changes: 49 additions & 0 deletions lib/Listener/AddMissingIndicesListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024 Joas Schilling <[email protected]>
*
* @author Joas Schilling <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Notifications\Listener;

use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<Event|AddMissingIndicesEvent>
*/
class AddMissingIndicesListener implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof AddMissingIndicesEvent)) {
// Unrelated
return;
}

$event->addMissingIndex(
'notifications_pushhash',
'oc_npushhash_di',
['deviceidentifier'],
);
}
}
1 change: 1 addition & 0 deletions lib/Migration/Version2010Date20210218082811.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a41fc4f

Please sign in to comment.