[CalendarServer-changes] [7285] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Apr 4 09:44:14 PDT 2011


Revision: 7285
          http://trac.macosforge.org/projects/calendarserver/changeset/7285
Author:   cdaboo at apple.com
Date:     2011-04-04 09:44:14 -0700 (Mon, 04 Apr 2011)
Log Message:
-----------
Avoid unnecessary ical/vcard object serializations when the text representation already exists.

Modified Paths:
--------------
    CalendarServer/trunk/contrib/tools/protocolanalysis.py
    CalendarServer/trunk/twistedcaldav/caldavxml.py
    CalendarServer/trunk/twistedcaldav/carddavxml.py
    CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py
    CalendarServer/trunk/twistedcaldav/method/put_common.py
    CalendarServer/trunk/twistedcaldav/storebridge.py

Modified: CalendarServer/trunk/contrib/tools/protocolanalysis.py
===================================================================
--- CalendarServer/trunk/contrib/tools/protocolanalysis.py	2011-04-04 16:42:28 UTC (rev 7284)
+++ CalendarServer/trunk/contrib/tools/protocolanalysis.py	2011-04-04 16:44:14 UTC (rev 7285)
@@ -511,9 +511,13 @@
     
     def getAdjustedMethodName(self):
 
+        try:
+            uribits = self.currentLine.uri.split('/')[1:]
+        except IndexError:
+            uribits = [self.currentLine.uri]
+
         if self.currentLine.method == "PROPFIND":
             
-            uribits = self.currentLine.uri.split('/')[1:]
             cached = "cached" in self.currentLine.extended
 
             if uribits[0] == "calendars":
@@ -551,7 +555,6 @@
             if "(" in self.currentLine.method:
                 report_type = self.currentLine.method.split("}" if "}" in self.currentLine.method else ":")[1][:-1]
                 if report_type == "addressbook-query":
-                    uribits = self.currentLine.uri.split('/')[1:]
                     if uribits[0] == "directory":
                         report_type = "directory-query"
                 shorter = {
@@ -569,15 +572,11 @@
         
         elif self.currentLine.method == "PROPPATCH":
             
-            uribits = self.currentLine.uri.split('/')[1:]
-            
             if uribits[0] == "calendars":
                 return "PROPPATCH Calendar"
             
         elif self.currentLine.method == "POST":
             
-            uribits = self.currentLine.uri.split('/')[1:]
-            
             if uribits[0] == "calendars" and len(uribits) > 3 and uribits[3] == "outbox":
                 if "freebusy" in self.currentLine.extended:
                     return "POST Freebusy"
@@ -621,15 +620,11 @@
             
         elif self.currentLine.method == "PUT":
             
-            uribits = self.currentLine.uri.split('/')[1:]
-            
             if len(uribits) > 3 and uribits[3] == "dropbox":
                 return "PUT Dropbox"
             
         elif self.currentLine.method == "GET":
             
-            uribits = self.currentLine.uri.split('/')[1:]
-            
             if uribits[0] == "calendars":
                 
                 if len(uribits) > 3:

Modified: CalendarServer/trunk/twistedcaldav/caldavxml.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/caldavxml.py	2011-04-04 16:42:28 UTC (rev 7284)
+++ CalendarServer/trunk/twistedcaldav/caldavxml.py	2011-04-04 16:44:14 UTC (rev 7285)
@@ -444,6 +444,8 @@
 
         return str(data)
 
+    textData = calendarData
+
 class CalendarComponent (CalDAVElement):
     """
     Defines which component types to return.

Modified: CalendarServer/trunk/twistedcaldav/carddavxml.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/carddavxml.py	2011-04-04 16:42:28 UTC (rev 7284)
+++ CalendarServer/trunk/twistedcaldav/carddavxml.py	2011-04-04 16:44:14 UTC (rev 7285)
@@ -297,6 +297,7 @@
 
         return str(data)
 
+    textData = addressData
 
 class AllProperties (CardDAVEmptyElement):
     """

Modified: CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py	2011-04-04 16:42:28 UTC (rev 7284)
+++ CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py	2011-04-04 16:44:14 UTC (rev 7285)
@@ -89,7 +89,7 @@
         request,
         source=None, source_uri=None, sourceparent=None, sourceadbk=False, deletesource=False,
         destination=None, destination_uri=None, destinationparent=None, destinationadbk=True,
-        vcard=None,
+        vcard=None, vcarddata=None,
         indexdestination = True,
    ):
         """
@@ -101,9 +101,10 @@
         @param source_uri:        the URI for the source resource.
         @param destination:       the L{CalDAVResource} for the destination resource to copy into.
         @param destination_uri:   the URI for the destination resource.
-        @param vcard:          the C{str} or L{Component} vcard data if there is no source, None otherwise.
-        @param sourceadbk:         True if the source resource is in a vcard collection, False otherwise.
-        @param destinationadbk:    True if the destination resource is in a vcard collection, False otherwise
+        @param vcard:             the C{str} or L{Component} vcard data if there is no source, None otherwise.
+        @param vcarddata:         the C{str} vcard data if there is no source, None otherwise. Optional.
+        @param sourceadbk:        True if the source resource is in a vcard collection, False otherwise.
+        @param destinationadbk:   True if the destination resource is in a vcard collection, False otherwise
         @param sourceparent:      the L{CalDAVResource} for the source resource's parent collection, or None if source is None.
         @param destinationparent: the L{CalDAVResource} for the destination resource's parent collection.
         @param deletesource:      True if the source resource is to be deleted on successful completion, False otherwise.
@@ -140,7 +141,7 @@
         self.destination_uri = destination_uri
         self.destinationparent = destinationparent
         self.vcard = vcard
-        self.vcarddata = None
+        self.vcarddata = vcarddata
         self.deletesource = deletesource
         self.indexdestination = indexdestination
         

Modified: CalendarServer/trunk/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_common.py	2011-04-04 16:42:28 UTC (rev 7284)
+++ CalendarServer/trunk/twistedcaldav/method/put_common.py	2011-04-04 16:44:14 UTC (rev 7285)
@@ -121,7 +121,7 @@
         request,
         source=None, source_uri=None, sourceparent=None, sourcecal=False, deletesource=False,
         destination=None, destination_uri=None, destinationparent=None, destinationcal=True,
-        calendar=None,
+        calendar=None, calendardata=None,
         isiTIP=False,
         allowImplicitSchedule=True,
         internal_request=False,
@@ -137,6 +137,7 @@
         @param destination:       the L{CalDAVResource} for the destination resource to copy into.
         @param destination_uri:   the URI for the destination resource.
         @param calendar:          the C{str} or L{Component} calendar data if there is no source, None otherwise.
+        @param calendardata:      the C{str} calendar data if there is no source, None otherwise. Optional
         @param sourcecal:         True if the source resource is in a calendar collection, False otherwise.
         @param destinationcal:    True if the destination resource is in a calendar collection, False otherwise
         @param sourceparent:      the L{CalDAVResource} for the source resource's parent collection, or None if source is None.
@@ -180,7 +181,7 @@
         self.destination_uri = destination_uri
         self.destinationparent = destinationparent
         self.calendar = calendar
-        self.calendardata = None
+        self.calendardata = calendardata
         self.deletesource = deletesource
         self.isiTIP = isiTIP
         self.allowImplicitSchedule = allowImplicitSchedule
@@ -558,7 +559,7 @@
             if not self.source and self.destination.exists() and self.destination.accessMode:
                 old_access = self.destination.accessMode
                 self.calendar.addProperty(Property(name=Component.ACCESS_PROPERTY, value=old_access))
-                self.calendardata = str(self.calendar)
+                self.calendardata = None
                 
         return succeed(None)
 
@@ -576,8 +577,8 @@
                    "Cannot truncate recurrences",
                 ))
             if result:
-                self.calendardata = str(self.calendar)
-                return result
+                self.calendardata = None
+            return result
         else:
             return False
 
@@ -824,7 +825,7 @@
                         returnValue(new_calendar)
                     else:
                         self.calendar = new_calendar
-                        self.calendardata = str(self.calendar)
+                        self.calendardata = None
                         data_changed = True
                 did_implicit_action = True
         else:
@@ -863,7 +864,7 @@
     def doStore(self, implicit):
 
         # Stash the current calendar data as we may need to return it
-        self.returndata = str(self.calendar)
+        self.returndata = str(self.calendar) if self.calendardata is None else self.calendardata
 
         # Always do the per-user data merge right before we store
         yield self.mergePerUserData()

Modified: CalendarServer/trunk/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/storebridge.py	2011-04-04 16:42:28 UTC (rev 7284)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py	2011-04-04 16:44:14 UTC (rev 7285)
@@ -549,21 +549,19 @@
         
         # Build response
         xmlresponses = []
-        for component in components:
+        for ctr, component in enumerate(components):
             
             code = None
             error = None
             dataChanged = None
             try:
-                componentdata = str(component)
-
                 # Create a new name if one was not provided
-                name =  md5(str(componentdata) + str(time.time()) + request.path).hexdigest() + self.resourceSuffix()
+                name =  md5(str(ctr) + component.resourceUID() + str(time.time()) + request.path).hexdigest() + self.resourceSuffix()
             
                 # Get a resource for the new item
                 newchildURL = joinURL(request.path, name)
                 newchild = (yield request.locateResource(newchildURL))
-                dataChanged = (yield self.storeResourceData(request, newchild, newchildURL, componentdata))
+                dataChanged = (yield self.storeResourceData(request, newchild, newchildURL, component))
 
             except HTTPError, e:
                 # Extract the pre-condition
@@ -644,6 +642,9 @@
         xmlresponses = []
         checkedBindPrivelege = None
         checkedUnbindPrivelege = None
+        createCount = 0
+        updateCount = 0
+        deleteCount = 0
         for xmlchild in xmlroot.children:
             
             # Determine the multiput operation: create, update, delete
@@ -666,7 +667,8 @@
                         checkedBindPrivelege = e
 
                 # Create operations
-                yield self.crudCreate(request, xmldata.generateComponent(), xmlresponses, return_changed, checkedBindPrivelege)
+                yield self.crudCreate(request, xmldata, xmlresponses, return_changed, checkedBindPrivelege)
+                createCount += 1
             else:
                 delete = xmlchild.childOfType(customxml.Delete.qname())
                 ifmatch = xmlchild.childOfType(customxml.IfMatch.qname())
@@ -677,7 +679,8 @@
                         raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, "Could not parse valid data from request body - no set of delete operation"))
                     if xmldata is None:
                         raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, "Could not parse valid data from request body for set operation"))
-                    yield self.crudUpdate(request, str(href), xmldata.generateComponent(), ifmatch, return_changed, xmlresponses)
+                    yield self.crudUpdate(request, str(href), xmldata, ifmatch, return_changed, xmlresponses)
+                    updateCount += 1
                 else:
                     # Do privilege check on collection once 
                     if checkedUnbindPrivelege is None:
@@ -688,6 +691,7 @@
                             checkedUnbindPrivelege = e
 
                     yield self.crudDelete(request, str(href), ifmatch, xmlresponses, checkedUnbindPrivelege);
+                    deleteCount += 1
         
         result = MultiStatusResponse(xmlresponses)
         
@@ -699,26 +703,34 @@
         if not hasattr(request, "extendedLogItems"):
             request.extendedLogItems = {}
         request.extendedLogItems["rcount"] = len(xmlresponses)
+        if createCount:
+            request.extendedLogItems["create"] = createCount
+        if updateCount:
+            request.extendedLogItems["update"] = updateCount
+        if deleteCount:
+            request.extendedLogItems["delete"] = deleteCount
 
         returnValue(result)
 
     @inlineCallbacks
-    def crudCreate(self, request, component, xmlresponses, return_changed, hasPrivilege):
+    def crudCreate(self, request, xmldata, xmlresponses, return_changed, hasPrivilege):
         
         code = None
         error = None
         try:
-            componentdata = str(component)
             if isinstance(hasPrivilege, HTTPError):
                 raise hasPrivilege
 
+            componentdata = xmldata.textData()
+            component = xmldata.generateComponent()
+
             # Create a new name if one was not provided
             name =  md5(str(componentdata) + str(time.time()) + request.path).hexdigest() + self.resourceSuffix()
         
             # Get a resource for the new item
             newchildURL = joinURL(request.path, name)
             newchild = (yield request.locateResource(newchildURL))
-            yield self.storeResourceData(request, newchild, newchildURL, componentdata)
+            yield self.storeResourceData(request, newchild, newchildURL, component, componentdata)
 
             # FIXME: figure out return_changed behavior
 
@@ -758,11 +770,12 @@
             )
 
     @inlineCallbacks
-    def crudUpdate(self, request, href, component, ifmatch, return_changed, xmlresponses):
+    def crudUpdate(self, request, href, xmldata, ifmatch, return_changed, xmlresponses):
         code = None
         error = None
         try:
-            componentdata = str(component)
+            componentdata = xmldata.textData()
+            component = xmldata.generateComponent()
 
             updateResource = (yield request.locateResource(href))
             if not updateResource.exists():
@@ -775,7 +788,7 @@
             if ifmatch and ifmatch != updateResource.etag().generate():
                 raise HTTPError(responsecode.PRECONDITION_FAILED)
             
-            yield self.storeResourceData(request, updateResource, href, componentdata)
+            yield self.storeResourceData(request, updateResource, href, component, componentdata)
 
             # FIXME: figure out return_changed behavior
 
@@ -1028,14 +1041,15 @@
         return caldavxml.CalendarData
 
     @inlineCallbacks
-    def storeResourceData(self, request, newchild, newchildURL, data):
+    def storeResourceData(self, request, newchild, newchildURL, component, text=None):
         storer = StoreCalendarObjectResource(
             request = request,
             destination = newchild,
             destination_uri = newchildURL,
             destinationcal = True,
             destinationparent = self,
-            calendar = data,
+            calendar = component,
+            calendardata = text,
         )
         yield storer.run()
         
@@ -1947,7 +1961,7 @@
         return carddavxml.AddressData
 
     @inlineCallbacks
-    def storeResourceData(self, request, newchild, newchildURL, data):
+    def storeResourceData(self, request, newchild, newchildURL, component, text=None):
         storer = StoreAddressObjectResource(
             request = request,
             sourceadbk = False,
@@ -1955,7 +1969,8 @@
             destination_uri = newchildURL,
             destinationadbk = True,
             destinationparent = self,
-            vcard = data,
+            vcard = component,
+            vcarddata = text,
         )
         yield storer.run()
         
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110404/b2b64df2/attachment-0001.html>


More information about the calendarserver-changes mailing list