From 9460803f71c6d49efe5ae87a7b2009de3c867ac8 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 28 Feb 2010 11:19:36 +1300 Subject: [PATCH] Add an option to restrict visible contents to a limited date range. This patch adds ability to hide old events from Caldav clients. New configuration option $c->hide_older_than accepts an integer number of days. For example, setting $c->hide_older_than=90 hides all events with "end date" older than 90 days. The main purpose of this patch is allowing to use Sunbird with more than 500 Caldav events without removing these events from calendar. Without this patch the Sunbird slows down and load calendars extremely slowly (up to 10 min. for 1800 events). --- inc/caldav-PROPFIND.php | 7 ++++++- inc/caldav-REPORT-calquery.php | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/inc/caldav-PROPFIND.php b/inc/caldav-PROPFIND.php index c7d2af73..4bf64da3 100644 --- a/inc/caldav-PROPFIND.php +++ b/inc/caldav-PROPFIND.php @@ -156,6 +156,11 @@ function get_collection_contents( $depth, $user_no, $collection ) { $privacy_clause = " AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) "; } + $time_limit_clause = ' '; + if ( isset($c->hide_older_than) && intval($c->hide_older_than > 0) ) { + $time_limit_clause = " AND calendar_item.dtstart > (now() - interval '".intval($c->hide_older_than)." days') "; + } + $sql = 'SELECT collection.*, principal.*, caldav_data.*, caldav_data, '; $sql .= "to_char(coalesce(calendar_item.created, caldav_data.created) at time zone 'GMT',$date_format) AS created, "; $sql .= "to_char(last_modified at time zone 'GMT',$date_format) AS modified, "; @@ -163,7 +168,7 @@ function get_collection_contents( $depth, $user_no, $collection ) { $sql .= 'calendar_item.* '; $sql .= 'FROM caldav_data LEFT JOIN calendar_item USING( dav_id, user_no, dav_name, collection_id) '; $sql .= 'LEFT JOIN collection USING(collection_id,user_no) LEFT JOIN principal USING(user_no) '; - $sql .= 'WHERE collection.dav_name = :collection_dav_name '. $privacy_clause; + $sql .= 'WHERE collection.dav_name = :collection_dav_name '.$time_limit_clause.' '.$privacy_clause; if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $sql .= " ORDER BY caldav_data.dav_id"; $qry = new AwlQuery( $sql, array( ':collection_dav_name' => $collection->dav_name()) ); if( $qry->Exec('PROPFIND',__LINE__,__FILE__) && $qry->rows() > 0 ) { diff --git a/inc/caldav-REPORT-calquery.php b/inc/caldav-REPORT-calquery.php index 6252b7d6..675efdcf 100644 --- a/inc/caldav-REPORT-calquery.php +++ b/inc/caldav-REPORT-calquery.php @@ -250,6 +250,10 @@ if ( isset($c->hide_TODO) && $c->hide_TODO && ! $request->AllowedTo('all') ) { $where .= "AND caldav_data.caldav_type NOT IN ('VTODO') "; } +if ( isset($c->hide_older_than) && intval($c->hide_older_than > 0) ) { + $where .= " AND calendar_item.dtstart > (now() - interval '".intval($c->hide_older_than)." days') "; +} + $sql = "SELECT * FROM caldav_data INNER JOIN calendar_item USING(dav_id,user_no,dav_name)". $where; if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $sql .= " ORDER BY dav_id"; $qry = new PgQuery( $sql );