From 77fae8cacc02f22fd23f506847b9d8449df0c4d2 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 3 May 2012 20:29:49 +1200 Subject: [PATCH] A more efficient query for GET including sub-collections. --- inc/caldav-GET-functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/inc/caldav-GET-functions.php b/inc/caldav-GET-functions.php index 8452632c..1558604c 100644 --- a/inc/caldav-GET-functions.php +++ b/inc/caldav-GET-functions.php @@ -45,8 +45,10 @@ function export_iCalendar( DAVResource $dav_resource ) { $sql = 'SELECT caldav_data, class, caldav_type, calendar_item.user_no, logged_user '; $sql .= 'FROM collection INNER JOIN caldav_data USING(collection_id) INNER JOIN calendar_item USING ( dav_id ) WHERE '; if ( isset($c->get_includes_subcollections) && $c->get_includes_subcollections ) { - $sql .= '(collection.dav_name ~ :path_match '; - $sql .= 'OR collection.collection_id IN (SELECT bound_source_id FROM dav_binding WHERE dav_binding.dav_name ~ :path_match)) '; + $sql .= 'caldav_data.collection_id IN '; + $sql .= '(SELECT bound_source_id FROM dav_binding WHERE dav_binding.dav_name ~ :path_match '; + $sql .= 'UNION '; + $sql .= 'SELECT collection_id FROM collection WHERE collection.dav_name ~ :path_match) '; $params = array( ':path_match' => '^'.$request->path ); } else {