[CalendarServer-changes] [6939] CalendarServer/branches/users/glyph/dalify/txdav/caldav/datastore/ sql.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 16 06:27:12 PST 2011


Revision: 6939
          http://trac.macosforge.org/projects/calendarserver/changeset/6939
Author:   glyph at apple.com
Date:     2011-02-16 06:27:12 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
dalify time_range inserts, plus some formatting

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/dalify/txdav/caldav/datastore/sql.py

Modified: CalendarServer/branches/users/glyph/dalify/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/dalify/txdav/caldav/datastore/sql.py	2011-02-16 14:27:01 UTC (rev 6938)
+++ CalendarServer/branches/users/glyph/dalify/txdav/caldav/datastore/sql.py	2011-02-16 14:27:12 UTC (rev 6939)
@@ -397,7 +397,8 @@
 
 
     @inlineCallbacks
-    def updateDatabase(self, component, expand_until=None, reCreate=False, inserting=False):
+    def updateDatabase(self, component,
+                       expand_until=None, reCreate=False, inserting=False):
         """
         Update the database tables for the new data being written.
 
@@ -407,8 +408,10 @@
 
         # Decide how far to expand based on the component
         master = component.masterComponent()
-        if master is None or not component.isRecurring() and not component.isRecurringUnbounded():
-            # When there is no master we have a set of overridden components - index them all.
+        if ( master is None or not component.isRecurring()
+             and not component.isRecurringUnbounded() ):
+            # When there is no master we have a set of overridden components -
+            #   index them all.
             # When there is one instance - index it.
             # When bounded - index all.
             expand = datetime.datetime(2100, 1, 1, 0, 0, 0, tzinfo=utc)
@@ -416,19 +419,22 @@
             if expand_until:
                 expand = expand_until
             else:
-                expand = datetime.date.today() + default_future_expansion_duration
-
-            if expand > (datetime.date.today() + maximum_future_expansion_duration):
+                expand = (datetime.date.today() +
+                          default_future_expansion_duration)
+            if expand > (datetime.date.today() +
+                         maximum_future_expansion_duration):
                 raise IndexedSearchException
-
         try:
-            instances = component.expandTimeRanges(expand, ignoreInvalidInstances=reCreate)
+            instances = component.expandTimeRanges(
+                expand, ignoreInvalidInstances=reCreate)
         except InvalidOverriddenInstanceError, e:
-            self.log_error("Invalid instance %s when indexing %s in %s" % (e.rid, self._name, self._calendar,))
-            
+            self.log_error("Invalid instance %s when indexing %s in %s" %
+                           (e.rid, self._name, self._calendar,))
+
             if self._txn._migrating:
                 # TODO: fix the data here by re-writing component then re-index
-                instances = component.expandTimeRanges(expand, ignoreInvalidInstances=True)
+                instances = component.expandTimeRanges(
+                    expand, ignoreInvalidInstances=True)
             else:
                 raise
 
@@ -452,12 +458,13 @@
                 self._attachment = _ATTACHMENTS_MODE_WRITE
                 self._dropboxID = (yield self.dropboxID())
             elif component.hasPropertyInAnyComponent("ATTACH"):
-                # FIXME: really we ought to check to see if the ATTACH properties have URI values
-                # and if those are pointing to our server dropbox collections and only then set
-                # the read mode
+                # FIXME: really we ought to check to see if the ATTACH
+                # properties have URI values and if those are pointing to our
+                # server dropbox collections and only then set the read mode
                 self._attachment = _ATTACHMENTS_MODE_READ
                 self._dropboxID = (yield self.dropboxID())
 
+        tr = schema.TIME_RANGE
         co = schema.CALENDAR_OBJECT
         values = {
             co.CALENDAR_RESOURCE_ID            : self._calendar._resourceID,
@@ -489,9 +496,9 @@
                             ).on(self._txn))[0][0]
             # Need to wipe the existing time-range for this and rebuild
             yield Delete(
-                From=schema.TIME_RANGE,
-                Where=schema.TIME_RANGE.CALENDAR_OBJECT_RESOURCE_ID ==
-                self._resourceID).on(self._txn)
+                From=tr,
+                Where=tr.CALENDAR_OBJECT_RESOURCE_ID == self._resourceID
+            ).on(self._txn)
 
         # CALENDAR_OBJECT table update
         for key in instances:
@@ -500,25 +507,18 @@
             end = instance.end.replace(tzinfo=utc)
             float = instance.start.tzinfo is None
             transp = instance.component.propertyValue("TRANSP") == "TRANSPARENT"
-            instanceid = (yield self._txn.execSQL(
-                """
-                insert into TIME_RANGE
-                (CALENDAR_RESOURCE_ID, CALENDAR_OBJECT_RESOURCE_ID, FLOATING, START_DATE, END_DATE, FBTYPE, TRANSPARENT)
-                 values
-                (%s, %s, %s, %s, %s, %s, %s)
-                 returning
-                INSTANCE_ID
-                """,
-                [
-                    self._calendar._resourceID,
-                    self._resourceID,
-                    float,
-                    start,
-                    end,
-                    icalfbtype_to_indexfbtype.get(instance.component.getFBType(), icalfbtype_to_indexfbtype["FREE"]),
-                    transp,
-                ],
-            ))[0][0]
+            instanceid = (yield Insert({
+                tr.CALENDAR_RESOURCE_ID        : self._calendar._resourceID,
+                tr.CALENDAR_OBJECT_RESOURCE_ID : self._resourceID,
+                tr.FLOATING                    : float,
+                tr.START_DATE                  : start,
+                tr.END_DATE                    : end,
+                tr.FBTYPE                      :
+                    icalfbtype_to_indexfbtype.get(
+                        instance.component.getFBType(),
+                        icalfbtype_to_indexfbtype["FREE"]),
+                tr.TRANSPARENT                 : transp,
+            }, Return=tr.INSTANCE_ID).on(self._txn))[0][0]
             peruserdata = component.perUserTransparency(instance.rid)
             for useruid, transp in peruserdata:
                 yield self._txn.execSQL(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/8a9e1e23/attachment.html>


More information about the calendarserver-changes mailing list