Skip to content

Commit

Permalink
Merge pull request #46036 from nextcloud/fix/issue-46015
Browse files Browse the repository at this point in the history
fix(dav): add missing database index for dav_shares
  • Loading branch information
SebastianKrupinski authored Jun 26, 2024
2 parents aa0bbd2 + ff7e2c1 commit 380a253
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
'OCA\\DAV\\Files\\Sharing\\PublicLinkCheckPlugin' => $baseDir . '/../lib/Files/Sharing/PublicLinkCheckPlugin.php',
'OCA\\DAV\\HookManager' => $baseDir . '/../lib/HookManager.php',
'OCA\\DAV\\Listener\\ActivityUpdaterListener' => $baseDir . '/../lib/Listener/ActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\AddMissingIndicesListener' => $baseDir . '/../lib/Listener/AddMissingIndicesListener.php',
'OCA\\DAV\\Listener\\AddressbookListener' => $baseDir . '/../lib/Listener/AddressbookListener.php',
'OCA\\DAV\\Listener\\BirthdayListener' => $baseDir . '/../lib/Listener/BirthdayListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => $baseDir . '/../lib/Listener/CalendarContactInteractionListener.php',
Expand Down
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Files\\Sharing\\PublicLinkCheckPlugin' => __DIR__ . '/..' . '/../lib/Files/Sharing/PublicLinkCheckPlugin.php',
'OCA\\DAV\\HookManager' => __DIR__ . '/..' . '/../lib/HookManager.php',
'OCA\\DAV\\Listener\\ActivityUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/ActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\AddMissingIndicesListener' => __DIR__ . '/..' . '/../lib/Listener/AddMissingIndicesListener.php',
'OCA\\DAV\\Listener\\AddressbookListener' => __DIR__ . '/..' . '/../lib/Listener/AddressbookListener.php',
'OCA\\DAV\\Listener\\BirthdayListener' => __DIR__ . '/..' . '/../lib/Listener/BirthdayListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarContactInteractionListener.php',
Expand Down
5 changes: 5 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use OCA\DAV\Events\SubscriptionDeletedEvent;
use OCA\DAV\HookManager;
use OCA\DAV\Listener\ActivityUpdaterListener;
use OCA\DAV\Listener\AddMissingIndicesListener;
use OCA\DAV\Listener\AddressbookListener;
use OCA\DAV\Listener\BirthdayListener;
use OCA\DAV\Listener\CalendarContactInteractionListener;
Expand Down Expand Up @@ -79,6 +80,7 @@
use OCP\Config\BeforePreferenceDeletedEvent;
use OCP\Config\BeforePreferenceSetEvent;
use OCP\Contacts\IManager as IContactsManager;
use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\Events\TrustedServerRemovedEvent;
use OCP\Files\AppData\IAppDataFactory;
Expand Down Expand Up @@ -129,6 +131,8 @@ public function register(IRegistrationContext $context): void {
/**
* Register event listeners
*/
$context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class);

$context->registerEventListener(CalendarCreatedEvent::class, ActivityUpdaterListener::class);
$context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
$context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
Expand Down Expand Up @@ -235,6 +239,7 @@ public function registerHooks(HookManager $hm,

// Here we should recalculate if reminders should be sent to new or old sharees
});

}

public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
Expand Down
35 changes: 35 additions & 0 deletions apps/dav/lib/Listener/AddMissingIndicesListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\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)) {
return;
}
$event->addMissingIndex(
'dav_shares',
'dav_shares_resourceid_type',
['resourceid', 'type']
);
$event->addMissingIndex(
'dav_shares',
'dav_shares_resourceid_access',
['resourceid', 'access']
);
}

}
3 changes: 3 additions & 0 deletions apps/dav/lib/Migration/Version1004Date20170825134824.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['principaluri', 'resourceid', 'type', 'publicuri'], 'dav_shares_index');
// modified on 2024-6-21 to add performance improving indices on new instances
$table->addIndex(['resourceid', 'type'], 'dav_shares_resourceid_type');
$table->addIndex(['resourceid', 'access'], 'dav_shares_resourceid_access');
}
return $schema;
}
Expand Down

0 comments on commit 380a253

Please sign in to comment.