Skip to content

Commit

Permalink
Merge pull request #39741 from jmcclelland/optimize-cal-query
Browse files Browse the repository at this point in the history
optimize calendar search query
  • Loading branch information
ChristophWurst committed Aug 9, 2023
2 parents df304bd + 4a98bb9 commit 42d1568
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Expand Up @@ -1845,9 +1845,13 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
->andWhere($innerQuery->expr()->eq('op.calendartype',
$outerQuery->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)));

$outerQuery->select('c.id', 'c.calendardata', 'c.componenttype', 'c.uid', 'c.uri')
->from('calendarobjects', 'c')
->where($outerQuery->expr()->isNull('deleted_at'));

// only return public items for shared calendars for now
if (isset($calendarInfo['{http://owncloud.org/ns}owner-principal']) === false || $calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) {
$innerQuery->andWhere($innerQuery->expr()->eq('c.classification',
$outerQuery->andWhere($outerQuery->expr()->eq('c.classification',
$outerQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC)));
}

Expand All @@ -1866,10 +1870,6 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
$this->db->escapeLikeParameter($pattern) . '%')));
}

$outerQuery->select('c.id', 'c.calendardata', 'c.componenttype', 'c.uid', 'c.uri')
->from('calendarobjects', 'c')
->where($outerQuery->expr()->isNull('deleted_at'));

if (isset($options['timerange'])) {
if (isset($options['timerange']['start']) && $options['timerange']['start'] instanceof DateTimeInterface) {
$outerQuery->andWhere($outerQuery->expr()->gt('lastoccurence',
Expand Down

0 comments on commit 42d1568

Please sign in to comment.