From a1e9b90433d4759227ce9813d8211792d4404a01 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Mon, 7 Aug 2023 10:49:13 -0400 Subject: [PATCH 1/2] optimize calendar search query see https://github.com/nextcloud/calendar/issues/4758 Signed-off-by: Jamie McClelland --- apps/dav/lib/CalDAV/CalDavBackend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index cad275be7a884..3c39c5404dc6c 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1839,7 +1839,7 @@ public function search(array $calendarInfo, $pattern, array $searchProperties, // 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))); } From ed342d9071a1fbdcd0ea15bffebcd030c6d0e769 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Mon, 7 Aug 2023 13:35:08 -0400 Subject: [PATCH 2/2] ensure outerquery ->where() function doesn't clobber earier ->andWhere() Signed-off-by: Jamie McClelland --- apps/dav/lib/CalDAV/CalDavBackend.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 3c39c5404dc6c..e49e47879b0e5 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1837,6 +1837,10 @@ 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']) { $outerQuery->andWhere($outerQuery->expr()->eq('c.classification', @@ -1858,10 +1862,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',