perf(caldav): Add multi users support in findPropertiesByPaths

Signed-off-by: Carl Schwan <carl.schwan@nextclound.com>
This commit is contained in:
Carl Schwan 2025-08-13 00:57:15 +02:00
parent 806fe6619f
commit 977541cedf
2 changed files with 26 additions and 26 deletions

View file

@ -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<string, array<string, string|bool>>
*/
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()
};
}
}

View file

@ -40,19 +40,21 @@ class PropertyMapper extends QBMapper {
}
/**
* @param string $userId
* @param string[] $paths
* @param array<string, string[]> $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);
}
}