[CalendarServer-changes] [6973] CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/ sql.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 16 06:33:53 PST 2011


Revision: 6973
          http://trac.macosforge.org/projects/calendarserver/changeset/6973
Author:   glyph at apple.com
Date:     2011-02-16 06:33:53 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
dalify CommonHomeChild.sharerHomeID

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

Modified: CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py	2011-02-16 14:33:41 UTC (rev 6972)
+++ CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py	2011-02-16 14:33:53 UTC (rev 6973)
@@ -1370,23 +1370,33 @@
     def ownerHome(self):
         return self._home
 
+
+    @classproperty
+    def _ownerHomeFromResourceQuery(cls):
+        """
+        DAL query to retrieve the home resource ID of the owner from the bound
+        home-child ID.
+        """
+        bind = cls._bindSchema
+        return Select([bind.HOME_RESOURCE_ID],
+                     From=bind,
+                     Where=(bind.RESOURCE_ID ==
+                            Parameter("resourceID")).And(
+                                bind.BIND_MODE == _BIND_MODE_OWN))
+
+
     @inlineCallbacks
     def sharerHomeID(self):
-        
-        # If this is not shared then our home is what we want
         if self._owned:
+            # If this was loaded by its owner then we can skip the query, since
+            # we already know who the owner is.
             returnValue(self._home._resourceID)
         else:
-            rid = (yield self._txn.execSQL("""
-                select %(column_HOME_RESOURCE_ID)s from %(name)s
-                where
-                  %(column_RESOURCE_ID)s = %%s and
-                  %(column_BIND_MODE)s = %%s
-                """ % self._bindTable,
-                [self._resourceID, _BIND_MODE_OWN]
-            ))[0][0]
+            rid = (yield self._ownerHomeFromResourceQuery.on(
+                self._txn, resourceID=self._resourceID))[0][0]
             returnValue(rid)
 
+
     def setSharingUID(self, uid):
         self.properties()._setPerUserUID(uid)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/d66b390b/attachment.html>


More information about the calendarserver-changes mailing list