# HG changeset patch # User Paul Boddie # Date 1497393032 -7200 # Node ID d219182e1817ce79a6125d7bae735e70bacb02a4 # Parent 666c7bfe500dfa7506c8ae649cccaec010a9ee92 Remove old free/busy periods when updating recurring event scheduling records. diff -r 666c7bfe500d -r d219182e1817 imiptools/freebusy/common.py --- a/imiptools/freebusy/common.py Wed Jun 14 00:21:20 2017 +0200 +++ b/imiptools/freebusy/common.py Wed Jun 14 00:30:32 2017 +0200 @@ -644,6 +644,13 @@ if i < len(self.periods) and self.periods[i] == period: del self.periods[i] + def remove_periods_before(self, period): + + "Remove the entries in the collection before 'period'." + + last = bisect_right(self.periods, period) + self.remove_periods(self.periods[:last]) + def remove_event_periods(self, uid, recurrenceid=None, participant=None): """ diff -r 666c7bfe500d -r d219182e1817 imiptools/freebusy/database.py --- a/imiptools/freebusy/database.py Wed Jun 14 00:21:20 2017 +0200 +++ b/imiptools/freebusy/database.py Wed Jun 14 00:30:32 2017 +0200 @@ -183,6 +183,27 @@ self.cursor.execute(query, values) + def remove_periods_before(self, period): + + "Remove the entries in the collection before 'period'." + + end = format_datetime(period.get_start_point()) + + columns, values = [], [] + + if end: + columns.append("end <= ?") + values.append(end) + + query, values = self.get_query( + "delete from %(table)s :condition" % { + "columns" : self.columnlist(self.period_columns), + "table" : self.table_name + }, + columns, values) + + self.cursor.execute(query, values) + def remove_event_periods(self, uid, recurrenceid=None, participant=None): """ diff -r 666c7bfe500d -r d219182e1817 tools/make_freebusy.py --- a/tools/make_freebusy.py Wed Jun 14 00:21:20 2017 +0200 +++ b/tools/make_freebusy.py Wed Jun 14 00:30:32 2017 +0200 @@ -40,6 +40,7 @@ from imiptools.dates import get_default_timezone, to_utc_datetime from imiptools.freebusy import FreeBusyCollection, FreeBusyGroupCollection, \ FreeBusyGroupPeriod +from imiptools.period import Period from imiptools.stores import get_store, get_publisher, get_journal def make_freebusy(client, participants, storage, store_and_publish, @@ -70,16 +71,14 @@ journal = client.get_journal() publisher = client.get_publisher() preferences = client.get_preferences() - - tzid = preferences.get("TZID") or get_default_timezone() - - # Get the size of the free/busy window. + tzid = client.get_tzid() - try: - window_size = int(preferences.get("window_size")) - except (TypeError, ValueError): - window_size = 100 - window_end = get_window_end(tzid, window_size) + # Get the start and end of the window. Note that the start is normally the + # current moment in time, but for testing we may choose a specific point in + # time instead. + + window_start = client.get_window_start() + window_end = client.get_window_end() providers = [] @@ -109,6 +108,10 @@ else: fb = storage.get_freebusy_for_other_for_update(user, participant) + # Remove periods before the window start. + + fb.remove_periods_before(Period(window_start, None)) + # Obtain event objects. objs = [] @@ -143,7 +146,8 @@ # Add each active period to the collection. - for p in obj.get_active_periods(recurrenceids, tzid, window_end): + for p in obj.get_active_periods(recurrenceids, tzid, + start=window_start, end=window_end): # Obtain a suitable period object.