From 806fe6619ff61eb1a0049c6b3539fbe67ba246ed Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 12 Aug 2025 23:59:17 +0200 Subject: [PATCH 1/4] perf(caldav): Fetch additional properties for multiple calendars in one query Instead of doing it for each calendar individually. Signed-off-by: Carl Schwan --- apps/dav/lib/CalDAV/CalendarProvider.php | 51 ++++++++++++++++++------ apps/dav/lib/Db/PropertyMapper.php | 9 +++-- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalendarProvider.php b/apps/dav/lib/CalDAV/CalendarProvider.php index 3cc4039ed36..f81d5d37460 100644 --- a/apps/dav/lib/CalDAV/CalendarProvider.php +++ b/apps/dav/lib/CalDAV/CalendarProvider.php @@ -36,9 +36,14 @@ class CalendarProvider implements ICalendarProvider { }); } - $iCalendars = []; + $additionalProperties = $this->getAdditionalPropertiesForCalendars($calendarInfos); + foreach ($calendarInfos as $calendarInfo) { - $calendarInfo = array_merge($calendarInfo, $this->getAdditionalProperties($calendarInfo['principaluri'], $calendarInfo['uri'])); + $user = str_replace('principals/users/', '', $calendarInfo['principaluri']); + $path = 'calendars/' . $user . '/' . $calendarInfo['uri']; + + $calendarInfo = array_merge($calendarInfo, $additionalProperties[$path] ?? []); + $calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger); $iCalendars[] = new CalendarImpl( $calendar, @@ -49,19 +54,39 @@ class CalendarProvider implements ICalendarProvider { return $iCalendars; } - public function getAdditionalProperties(string $principalUri, string $calendarUri): array { - $user = str_replace('principals/users/', '', $principalUri); - $path = 'calendars/' . $user . '/' . $calendarUri; - - $properties = $this->propertyMapper->findPropertiesByPath($user, $path); + /** + * @param array{ + * principalUri: string, + * uri: string, + * }[] $uris + * @return array> + */ + private function getAdditionalPropertiesForCalendars(array $uris): array { + $users = []; + foreach ($uris as $uri) { + $user = str_replace('principals/users/', '', $uri['principaluri']); + if (!array_key_exists($user, $users)) { + $users[$user] = []; + } + $users[$user][] = 'calendars/' . $user . '/' . $uri['uri']; + } $list = []; - foreach ($properties as $property) { - if ($property instanceof Property) { - $list[$property->getPropertyname()] = match ($property->getPropertyname()) { - '{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(), - default => $property->getPropertyvalue() - }; + foreach ($users as $user => $calendars) { + $properties = $this->propertyMapper->findPropertiesByPaths($user, $calendars); + + $list = []; + foreach ($properties as $property) { + if ($property instanceof Property) { + if (!isset($list[$property->getPropertypath()])) { + $list[$property->getPropertypath()] = []; + } + + $list[$property->getPropertypath()][$property->getPropertyname()] = match ($property->getPropertyname()) { + '{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(), + default => $property->getPropertyvalue() + }; + } } } diff --git a/apps/dav/lib/Db/PropertyMapper.php b/apps/dav/lib/Db/PropertyMapper.php index 1789194ee7a..e509c684347 100644 --- a/apps/dav/lib/Db/PropertyMapper.php +++ b/apps/dav/lib/Db/PropertyMapper.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace OCA\DAV\Db; use OCP\AppFramework\Db\QBMapper; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; /** @@ -39,17 +40,19 @@ class PropertyMapper extends QBMapper { } /** + * @param string $userId + * @param string[] $paths * @return Property[] + * @throws \OCP\DB\Exception */ - public function findPropertiesByPath(string $userId, string $path): array { + public function findPropertiesByPaths(string $userId, array $paths): array { $selectQb = $this->db->getQueryBuilder(); $selectQb->select('*') ->from(self::TABLE_NAME) ->where( $selectQb->expr()->eq('userid', $selectQb->createNamedParameter($userId)), - $selectQb->expr()->eq('propertypath', $selectQb->createNamedParameter($path)), + $selectQb->expr()->in('propertypath', $selectQb->createNamedParameter($paths, IQueryBuilder::PARAM_STR_ARRAY)), ); return $this->findEntities($selectQb); } - } From 977541cedf110d3071b203275161795f6b69e9ea Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 13 Aug 2025 00:57:15 +0200 Subject: [PATCH 2/4] perf(caldav): Add multi users support in findPropertiesByPaths Signed-off-by: Carl Schwan --- apps/dav/lib/CalDAV/CalendarProvider.php | 38 +++++++++++------------- apps/dav/lib/Db/PropertyMapper.php | 14 +++++---- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalendarProvider.php b/apps/dav/lib/CalDAV/CalendarProvider.php index f81d5d37460..da8f6819bdf 100644 --- a/apps/dav/lib/CalDAV/CalendarProvider.php +++ b/apps/dav/lib/CalDAV/CalendarProvider.php @@ -37,7 +37,7 @@ class CalendarProvider implements ICalendarProvider { } $additionalProperties = $this->getAdditionalPropertiesForCalendars($calendarInfos); - + $iCalendars = []; foreach ($calendarInfos as $calendarInfo) { $user = str_replace('principals/users/', '', $calendarInfo['principaluri']); $path = 'calendars/' . $user . '/' . $calendarInfo['uri']; @@ -56,37 +56,35 @@ class CalendarProvider implements ICalendarProvider { /** * @param array{ - * principalUri: string, + * principaluri: string, * uri: string, * }[] $uris * @return array> */ private function getAdditionalPropertiesForCalendars(array $uris): array { - $users = []; + $calendars = []; foreach ($uris as $uri) { + /** @var string $user */ $user = str_replace('principals/users/', '', $uri['principaluri']); - if (!array_key_exists($user, $users)) { - $users[$user] = []; + if (!array_key_exists($user, $calendars)) { + $calendars[$user] = []; } - $users[$user][] = 'calendars/' . $user . '/' . $uri['uri']; + $calendars[$user][] = 'calendars/' . $user . '/' . $uri['uri']; } + $properties = $this->propertyMapper->findPropertiesByPaths($calendars); + $list = []; - foreach ($users as $user => $calendars) { - $properties = $this->propertyMapper->findPropertiesByPaths($user, $calendars); - - $list = []; - foreach ($properties as $property) { - if ($property instanceof Property) { - if (!isset($list[$property->getPropertypath()])) { - $list[$property->getPropertypath()] = []; - } - - $list[$property->getPropertypath()][$property->getPropertyname()] = match ($property->getPropertyname()) { - '{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(), - default => $property->getPropertyvalue() - }; + foreach ($properties as $property) { + if ($property instanceof Property) { + if (!isset($list[$property->getPropertypath()])) { + $list[$property->getPropertypath()] = []; } + + $list[$property->getPropertypath()][$property->getPropertyname()] = match ($property->getPropertyname()) { + '{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(), + default => $property->getPropertyvalue() + }; } } diff --git a/apps/dav/lib/Db/PropertyMapper.php b/apps/dav/lib/Db/PropertyMapper.php index e509c684347..86db8cfdbe6 100644 --- a/apps/dav/lib/Db/PropertyMapper.php +++ b/apps/dav/lib/Db/PropertyMapper.php @@ -40,19 +40,21 @@ class PropertyMapper extends QBMapper { } /** - * @param string $userId - * @param string[] $paths + * @param array $calendars * @return Property[] * @throws \OCP\DB\Exception */ - public function findPropertiesByPaths(string $userId, array $paths): array { + public function findPropertiesByPaths(array $calendars): array { $selectQb = $this->db->getQueryBuilder(); $selectQb->select('*') - ->from(self::TABLE_NAME) - ->where( - $selectQb->expr()->eq('userid', $selectQb->createNamedParameter($userId)), + ->from(self::TABLE_NAME); + + foreach ($calendars as $user => $paths) { + $selectQb->andWhere( + $selectQb->expr()->eq('userid', $selectQb->createNamedParameter($user)), $selectQb->expr()->in('propertypath', $selectQb->createNamedParameter($paths, IQueryBuilder::PARAM_STR_ARRAY)), ); + } return $this->findEntities($selectQb); } } From 46f0c6ebb59b992a14c81e2cf567d38db54aa601 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 13 Aug 2025 11:03:40 +0200 Subject: [PATCH 3/4] perf(caldav): Cache calendars in CustomPropertiesBackend We already do that for files, we are now also doing for calendars. With relatively small amount of calendars, I managed to reduce the number of DB requests by 35% and from 23 DB requests touching the oc_properties table to only 3. Signed-off-by: Carl Schwan --- apps/dav/lib/CalDAV/Calendar.php | 6 +- apps/dav/lib/CalDAV/CalendarProvider.php | 2 +- .../dav/lib/Connector/Sabre/ServerFactory.php | 2 + apps/dav/lib/DAV/CustomPropertiesBackend.php | 77 ++++++++++++++++++- apps/dav/lib/Db/Property.php | 1 + apps/dav/lib/Db/PropertyMapper.php | 25 +++++- apps/dav/lib/Server.php | 2 + .../Sabre/CustomPropertiesBackendTest.php | 2 + .../unit/DAV/CustomPropertiesBackendTest.php | 5 ++ 9 files changed, 113 insertions(+), 9 deletions(-) diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php index dd3a4cf3f69..deb00caa93d 100644 --- a/apps/dav/lib/CalDAV/Calendar.php +++ b/apps/dav/lib/CalDAV/Calendar.php @@ -36,7 +36,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable public function __construct( BackendInterface $caldavBackend, - $calendarInfo, + array $calendarInfo, IL10N $l10n, private IConfig $config, private LoggerInterface $logger, @@ -60,6 +60,10 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable $this->l10n = $l10n; } + public function getUri(): string { + return $this->calendarInfo['uri']; + } + /** * {@inheritdoc} * @throws Forbidden diff --git a/apps/dav/lib/CalDAV/CalendarProvider.php b/apps/dav/lib/CalDAV/CalendarProvider.php index da8f6819bdf..a8b818e59aa 100644 --- a/apps/dav/lib/CalDAV/CalendarProvider.php +++ b/apps/dav/lib/CalDAV/CalendarProvider.php @@ -72,7 +72,7 @@ class CalendarProvider implements ICalendarProvider { $calendars[$user][] = 'calendars/' . $user . '/' . $uri['uri']; } - $properties = $this->propertyMapper->findPropertiesByPaths($calendars); + $properties = $this->propertyMapper->findPropertiesByPathsAndUsers($calendars); $list = []; foreach ($properties as $property) { diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index a6a27057177..38fd057bc91 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -14,6 +14,7 @@ use OCA\DAV\CalDAV\DefaultCalendarValidator; use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\DAV\CustomPropertiesBackend; use OCA\DAV\DAV\ViewOnlyPlugin; +use OCA\DAV\Db\PropertyMapper; use OCA\DAV\Files\BrowserErrorPagePlugin; use OCA\DAV\Files\Sharing\RootCollection; use OCA\DAV\Upload\CleanupService; @@ -226,6 +227,7 @@ class ServerFactory { $tree, $this->databaseConnection, $this->userSession->getUser(), + \OCP\Server::get(PropertyMapper::class), \OCP\Server::get(DefaultCalendarValidator::class), ) ) diff --git a/apps/dav/lib/DAV/CustomPropertiesBackend.php b/apps/dav/lib/DAV/CustomPropertiesBackend.php index f9a4f8ee986..c2b80ff9d4a 100644 --- a/apps/dav/lib/DAV/CustomPropertiesBackend.php +++ b/apps/dav/lib/DAV/CustomPropertiesBackend.php @@ -9,13 +9,20 @@ namespace OCA\DAV\DAV; use Exception; +use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Calendar; +use OCA\DAV\CalDAV\CalendarHome; use OCA\DAV\CalDAV\CalendarObject; use OCA\DAV\CalDAV\DefaultCalendarValidator; +use OCA\DAV\CalDAV\Integration\ExternalCalendar; +use OCA\DAV\CalDAV\Outbox; +use OCA\DAV\CalDAV\Trashbin\TrashbinHome; use OCA\DAV\Connector\Sabre\Directory; +use OCA\DAV\Db\PropertyMapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IUser; +use Sabre\CalDAV\Schedule\Inbox; use Sabre\DAV\Exception as DavException; use Sabre\DAV\PropertyStorage\Backend\BackendInterface; use Sabre\DAV\PropFind; @@ -98,10 +105,9 @@ class CustomPropertiesBackend implements BackendInterface { /** * Properties cache - * - * @var array */ - private $userCache = []; + private array $userCache = []; + private array $publishedCache = []; private XmlService $xmlService; /** @@ -114,6 +120,7 @@ class CustomPropertiesBackend implements BackendInterface { private Tree $tree, private IDBConnection $connection, private IUser $user, + private PropertyMapper $propertyMapper, private DefaultCalendarValidator $defaultCalendarValidator, ) { $this->xmlService = new XmlService(); @@ -197,6 +204,13 @@ class CustomPropertiesBackend implements BackendInterface { $this->cacheDirectory($path, $node); } + if ($node instanceof CalendarHome && $propFind->getDepth() !== 0) { + $backend = $node->getCalDAVBackend(); + if ($backend instanceof CalDavBackend) { + $this->cacheCalendars($node, $requestedProps); + } + } + if ($node instanceof CalendarObject) { // No custom properties supported on individual events return; @@ -316,6 +330,10 @@ class CustomPropertiesBackend implements BackendInterface { return []; } + if (isset($this->publishedCache[$path])) { + return $this->publishedCache[$path]; + } + $qb = $this->connection->getQueryBuilder(); $qb->select('*') ->from(self::TABLE_NAME) @@ -326,6 +344,7 @@ class CustomPropertiesBackend implements BackendInterface { $props[$row['propertyname']] = $this->decodeValueFromDatabase($row['propertyvalue'], $row['valuetype']); } $result->closeCursor(); + $this->publishedCache[$path] = $props; return $props; } @@ -364,6 +383,58 @@ class CustomPropertiesBackend implements BackendInterface { $this->userCache = array_merge($this->userCache, $propsByPath); } + private function cacheCalendars(CalendarHome $node): void { + $calendars = $node->getChildren(); + + $users = []; + foreach ($calendars as $calendar) { + if ($calendar instanceof Calendar) { + $user = str_replace('principals/users/', '', $calendar->getPrincipalURI()); + if (!isset($users[$user])) { + $users[$user] = ['calendars/' . $user]; + } + $users[$user][] = 'calendars/' . $user . '/' . $calendar->getUri(); + } elseif ($calendar instanceof Inbox || $calendar instanceof Outbox || $calendar instanceof TrashbinHome || $calendar instanceof ExternalCalendar) { + if ($calendar->getOwner()) { + $user = str_replace('principals/users/', '', $calendar->getOwner()); + if (!isset($users[$user])) { + $users[$user] = ['calendars/' . $user]; + } + $users[$user][] = 'calendars/' . $user . '/' . $calendar->getName(); + } + } + } + + // user properties + $properties = $this->propertyMapper->findPropertiesByPathsAndUsers($users); + + $propsByPath = []; + foreach ($users as $paths) { + foreach ($paths as $path) { + $propsByPath[$path] = []; + } + } + + foreach ($properties as $property) { + $propsByPath[$property->getPropertypath()][$property->getPropertyname()] = $this->decodeValueFromDatabase($property->getPropertyvalue(), $property->getValuetype()); + } + $this->userCache = array_merge($this->userCache, $propsByPath); + + // published properties + $paths = []; + foreach ($users as $nestedPaths) { + $paths = array_merge($paths, $nestedPaths); + } + $paths = array_unique($paths); + + $propsByPath = array_fill_keys(array_values($paths), []); + $properties = $this->propertyMapper->findPropertiesByPaths($paths); + foreach ($properties as $property) { + $propsByPath[$property->getPropertypath()][$property->getPropertyname()] = $this->decodeValueFromDatabase($property->getPropertyvalue(), $property->getValuetype()); + } + $this->publishedCache = array_merge($this->publishedCache, $propsByPath); + } + /** * Returns a list of properties for the given path and current user * diff --git a/apps/dav/lib/Db/Property.php b/apps/dav/lib/Db/Property.php index 96c5f75ef4f..6c1e249ac47 100644 --- a/apps/dav/lib/Db/Property.php +++ b/apps/dav/lib/Db/Property.php @@ -16,6 +16,7 @@ use OCP\AppFramework\Db\Entity; * @method string getPropertypath() * @method string getPropertyname() * @method string getPropertyvalue() + * @method int getValuetype() */ class Property extends Entity { diff --git a/apps/dav/lib/Db/PropertyMapper.php b/apps/dav/lib/Db/PropertyMapper.php index 86db8cfdbe6..0ce2fa90a6f 100644 --- a/apps/dav/lib/Db/PropertyMapper.php +++ b/apps/dav/lib/Db/PropertyMapper.php @@ -44,17 +44,34 @@ class PropertyMapper extends QBMapper { * @return Property[] * @throws \OCP\DB\Exception */ - public function findPropertiesByPaths(array $calendars): array { + public function findPropertiesByPathsAndUsers(array $calendars): array { $selectQb = $this->db->getQueryBuilder(); $selectQb->select('*') ->from(self::TABLE_NAME); foreach ($calendars as $user => $paths) { - $selectQb->andWhere( - $selectQb->expr()->eq('userid', $selectQb->createNamedParameter($user)), - $selectQb->expr()->in('propertypath', $selectQb->createNamedParameter($paths, IQueryBuilder::PARAM_STR_ARRAY)), + $selectQb->orWhere( + $selectQb->expr()->andX( + $selectQb->expr()->eq('userid', $selectQb->createNamedParameter($user)), + $selectQb->expr()->in('propertypath', $selectQb->createNamedParameter($paths, IQueryBuilder::PARAM_STR_ARRAY)), + ) ); } + + return $this->findEntities($selectQb); + } + + /** + * @param string[] $calendars + * @return Property[] + * @throws \OCP\DB\Exception + */ + public function findPropertiesByPaths(array $calendars): array { + $selectQb = $this->db->getQueryBuilder(); + $selectQb->select('*') + ->from(self::TABLE_NAME) + ->where($selectQb->expr()->in('propertypath', $selectQb->createNamedParameter($calendars, IQueryBuilder::PARAM_STR_ARRAY))); + return $this->findEntities($selectQb); } } diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index a92e162f1b0..5d759851372 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -54,6 +54,7 @@ use OCA\DAV\Connector\Sabre\ZipFolderPlugin; use OCA\DAV\DAV\CustomPropertiesBackend; use OCA\DAV\DAV\PublicAuth; use OCA\DAV\DAV\ViewOnlyPlugin; +use OCA\DAV\Db\PropertyMapper; use OCA\DAV\Events\SabrePluginAddEvent; use OCA\DAV\Events\SabrePluginAuthInitEvent; use OCA\DAV\Files\BrowserErrorPagePlugin; @@ -306,6 +307,7 @@ class Server { $this->server->tree, \OCP\Server::get(IDBConnection::class), \OCP\Server::get(IUserSession::class)->getUser(), + \OCP\Server::get(PropertyMapper::class), \OCP\Server::get(DefaultCalendarValidator::class), ) ) diff --git a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php index d4021a66299..cafbdd3ca40 100644 --- a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php @@ -12,6 +12,7 @@ use OCA\DAV\CalDAV\DefaultCalendarValidator; use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\File; use OCA\DAV\DAV\CustomPropertiesBackend; +use OCA\DAV\Db\PropertyMapper; use OCP\IDBConnection; use OCP\IUser; use OCP\Server; @@ -52,6 +53,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { $this->tree, Server::get(IDBConnection::class), $this->user, + Server::get(PropertyMapper::class), $this->defaultCalendarValidator, ); } diff --git a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php index 2a85c0cbecd..517969fc9a3 100644 --- a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php @@ -10,6 +10,7 @@ namespace OCA\DAV\Tests\unit\DAV; use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\DefaultCalendarValidator; use OCA\DAV\DAV\CustomPropertiesBackend; +use OCA\DAV\Db\PropertyMapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IUser; @@ -36,6 +37,7 @@ class CustomPropertiesBackendTest extends TestCase { private IUser&MockObject $user; private DefaultCalendarValidator&MockObject $defaultCalendarValidator; private CustomPropertiesBackend $backend; + private PropertyMapper $propertyMapper; protected function setUp(): void { parent::setUp(); @@ -49,6 +51,7 @@ class CustomPropertiesBackendTest extends TestCase { ->with() ->willReturn('dummy_user_42'); $this->dbConnection = \OCP\Server::get(IDBConnection::class); + $this->propertyMapper = \OCP\Server::get(PropertyMapper::class); $this->defaultCalendarValidator = $this->createMock(DefaultCalendarValidator::class); $this->backend = new CustomPropertiesBackend( @@ -56,6 +59,7 @@ class CustomPropertiesBackendTest extends TestCase { $this->tree, $this->dbConnection, $this->user, + $this->propertyMapper, $this->defaultCalendarValidator, ); } @@ -129,6 +133,7 @@ class CustomPropertiesBackendTest extends TestCase { $this->tree, $db, $this->user, + $this->propertyMapper, $this->defaultCalendarValidator, ); From 9df79bae105652bfba23f3677b199c3cdb866d03 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 14 Aug 2025 11:46:26 +0200 Subject: [PATCH 4/4] perf(caldav): Only prefetch published properties Signed-off-by: Carl Schwan --- apps/dav/lib/DAV/CustomPropertiesBackend.php | 8 ++++++-- apps/dav/lib/Db/PropertyMapper.php | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/dav/lib/DAV/CustomPropertiesBackend.php b/apps/dav/lib/DAV/CustomPropertiesBackend.php index c2b80ff9d4a..e9b2137178d 100644 --- a/apps/dav/lib/DAV/CustomPropertiesBackend.php +++ b/apps/dav/lib/DAV/CustomPropertiesBackend.php @@ -383,7 +383,7 @@ class CustomPropertiesBackend implements BackendInterface { $this->userCache = array_merge($this->userCache, $propsByPath); } - private function cacheCalendars(CalendarHome $node): void { + private function cacheCalendars(CalendarHome $node, array $requestedProperties): void { $calendars = $node->getChildren(); $users = []; @@ -421,6 +421,10 @@ class CustomPropertiesBackend implements BackendInterface { $this->userCache = array_merge($this->userCache, $propsByPath); // published properties + $allowedProps = array_intersect(self::PUBLISHED_READ_ONLY_PROPERTIES, $requestedProperties); + if (empty($allowedProps)) { + return; + } $paths = []; foreach ($users as $nestedPaths) { $paths = array_merge($paths, $nestedPaths); @@ -428,7 +432,7 @@ class CustomPropertiesBackend implements BackendInterface { $paths = array_unique($paths); $propsByPath = array_fill_keys(array_values($paths), []); - $properties = $this->propertyMapper->findPropertiesByPaths($paths); + $properties = $this->propertyMapper->findPropertiesByPaths($paths, $allowedProps); foreach ($properties as $property) { $propsByPath[$property->getPropertypath()][$property->getPropertyname()] = $this->decodeValueFromDatabase($property->getPropertyvalue(), $property->getValuetype()); } diff --git a/apps/dav/lib/Db/PropertyMapper.php b/apps/dav/lib/Db/PropertyMapper.php index 0ce2fa90a6f..a3dbdaa7d98 100644 --- a/apps/dav/lib/Db/PropertyMapper.php +++ b/apps/dav/lib/Db/PropertyMapper.php @@ -63,15 +63,20 @@ class PropertyMapper extends QBMapper { /** * @param string[] $calendars + * @param string[] $allowedProperties * @return Property[] * @throws \OCP\DB\Exception */ - public function findPropertiesByPaths(array $calendars): array { + public function findPropertiesByPaths(array $calendars, array $allowedProperties = []): array { $selectQb = $this->db->getQueryBuilder(); $selectQb->select('*') ->from(self::TABLE_NAME) ->where($selectQb->expr()->in('propertypath', $selectQb->createNamedParameter($calendars, IQueryBuilder::PARAM_STR_ARRAY))); + if ($allowedProperties) { + $selectQb->andWhere($selectQb->expr()->in('propertyname', $selectQb->createNamedParameter($allowedProperties, IQueryBuilder::PARAM_STR_ARRAY))); + } + return $this->findEntities($selectQb); } }