diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-03-27 17:48:43 +0100 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-03-27 20:04:23 +0100 |
commit | 4bdb473aae8307d4be59bc7975eca4e6e962c739 (patch) | |
tree | 5bc4bf3b738de15feeee4feb822f8001dd4cb313 /apps/dav/tests | |
parent | 9afcec721fdc75c876bb62cc2de8295280ed4810 (diff) | |
download | nextcloud-server-4bdb473aae8307d4be59bc7975eca4e6e962c739.tar.gz nextcloud-server-4bdb473aae8307d4be59bc7975eca4e6e962c739.zip |
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]: https://github.com/nextcloud/calendar/blob/b3670f1805ef9ef952d6abe4e5334e37b5a14133/src/services/caldavService.js#L43
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php b/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php index c99a859ac16..24b72117658 100644 --- a/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php @@ -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()); + } } |