Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db): Add index on device identifier for quicker deletion #1806

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading