perf(caldav): Only prefetch published properties

Signed-off-by: Carl Schwan <carl.schwan@nextclound.com>
pull/54386/head
Carl Schwan 2 months ago
parent 46f0c6ebb5
commit 9df79bae10
  1. 8
      apps/dav/lib/DAV/CustomPropertiesBackend.php
  2. 7
      apps/dav/lib/Db/PropertyMapper.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());
}

@ -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);
}
}

Loading…
Cancel
Save