mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
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>
This commit is contained in:
parent
9afcec721f
commit
4bdb473aae
2 changed files with 62 additions and 0 deletions
|
|
@ -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…
Reference in a new issue