perf(dav): skip non-calendar requests in webcal caching plugin

The webcal caching plugin is active when the X-NC-CalDAV-Webcal-Caching header is there.

findPrincipalByUrl sends a request for /remote.php/dav/principals/users/admin/ using the caldavService which sets the header by default.[^1]

As X-NC-CalDAV-Webcal-Caching only impacts calendar requests, we can skip non-calendar requests.

[^1]: b3670f1805/src/services/caldavService.js (L43)

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
pull/44511/head
Daniel Kesselberg 2 years ago
parent 9afcec721f
commit 4bdb473aae
No known key found for this signature in database
GPG Key ID: 36E3664E099D0614
  1. 4
      apps/dav/lib/CalDAV/WebcalCaching/Plugin.php
  2. 58
      apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php

@ -98,6 +98,10 @@ class Plugin extends ServerPlugin {
}
$path = $request->getPath();
if (!str_starts_with($path, 'calendars/')) {
return;
}
$pathParts = explode('/', ltrim($path, '/'));
if (\count($pathParts) < 2) {
return;

@ -25,6 +25,10 @@ namespace OCA\DAV\Tests\unit\CalDAV\WebcalCaching;
use OCA\DAV\CalDAV\WebcalCaching\Plugin;
use OCP\IRequest;
use Sabre\DAV\Server;
use Sabre\DAV\Tree;
use Sabre\HTTP\Request;
use Sabre\HTTP\Response;
class PluginTest extends \Test\TestCase {
public function testDisabled(): void {
@ -60,4 +64,58 @@ class PluginTest extends \Test\TestCase {
$this->assertEquals(true, $plugin->isCachingEnabledForThisRequest());
}
public function testSkipNonCalendarRequest(): void {
$request = $this->createMock(IRequest::class);
$request->expects($this->once())
->method('isUserAgent')
->with(Plugin::ENABLE_FOR_CLIENTS)
->willReturn(false);
$request->expects($this->once())
->method('getHeader')
->with('X-NC-CalDAV-Webcal-Caching')
->willReturn('On');
$sabreRequest = new Request('REPORT', '/remote.php/dav/principals/users/admin/');
$sabreRequest->setBaseUrl('/remote.php/dav/');
$tree = $this->createMock(Tree::class);
$tree->expects($this->never())
->method('getNodeForPath');
$server = new Server($tree);
$plugin = new Plugin($request);
$plugin->initialize($server);
$plugin->beforeMethod($sabreRequest, new Response());
}
public function testProcessCalendarRequest(): void {
$request = $this->createMock(IRequest::class);
$request->expects($this->once())
->method('isUserAgent')
->with(Plugin::ENABLE_FOR_CLIENTS)
->willReturn(false);
$request->expects($this->once())
->method('getHeader')
->with('X-NC-CalDAV-Webcal-Caching')
->willReturn('On');
$sabreRequest = new Request('REPORT', '/remote.php/dav/calendars/admin/personal/');
$sabreRequest->setBaseUrl('/remote.php/dav/');
$tree = $this->createMock(Tree::class);
$tree->expects($this->once())
->method('getNodeForPath');
$server = new Server($tree);
$plugin = new Plugin($request);
$plugin->initialize($server);
$plugin->beforeMethod($sabreRequest, new Response());
}
}

Loading…
Cancel
Save