From 9df79bae105652bfba23f3677b199c3cdb866d03 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 14 Aug 2025 11:46:26 +0200 Subject: [PATCH] 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); } }