[CalendarServer-changes] [9494] CalendarServer/branches/users/gaya/inviteclean/txdav/common/ datastore/sql.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 24 19:19:48 PDT 2012


Revision: 9494
          http://trac.macosforge.org/projects/calendarserver/changeset/9494
Author:   gaya at apple.com
Date:     2012-07-24 19:19:47 -0700 (Tue, 24 Jul 2012)
Log Message:
-----------
combine asShared() and asInvited()

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-25 00:31:47 UTC (rev 9493)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-25 02:19:47 UTC (rev 9494)
@@ -2287,32 +2287,19 @@
                         )
         )
 
-
     @classproperty
     def _sharedFor(cls): #@NoSelf
         bind = cls._bindSchema
         return cls._bindEntriesFor(bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
     
-
     @inlineCallbacks
-    def asShared(self):
-        """
-        Retrieve all the versions of this L{CommonHomeChild} as it is shared to
-        everyone.
+    def _asBound(self, query):
+        rows = yield query.on(self._txn, 
+                                resourceID=self._resourceID)
 
-        @see: L{ICalendarHome.asShared}
-
-        @return: L{CommonHomeChild} objects that represent this
-            L{CommonHomeChild} as a child of different L{CommonHome}s
-        @rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
-        """
-        rows = yield self._sharedFor.on(self._txn, 
-                                        resourceID=self._resourceID)
-
         cls = self.__class__ # for ease of grepping...
         result = []
         for bindMode, homeResourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in rows:
-            assert bindStatus == _BIND_STATUS_ACCEPTED
             # TODO: this could all be issued in parallel; no need to serialize
             # the loop.
             new = cls(
@@ -2325,8 +2312,24 @@
             yield new.initFromStore()
             result.append(new)
         returnValue(result)
+    
 
+    @inlineCallbacks
+    def asShared(self):
+        """
+        Retrieve all the versions of this L{CommonHomeChild} as it is shared to
+        everyone.
 
+        @see: L{ICalendarHome.asShared}
+
+        @return: L{CommonHomeChild} objects that represent this
+            L{CommonHomeChild} as a child of different L{CommonHome}s
+        @rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
+        """
+        result = yield self._asBound(self._sharedFor)
+        returnValue(result)
+
+
     @classproperty
     def _invitedFor(cls): #@NoSelf
         bind = cls._bindSchema
@@ -2344,28 +2347,9 @@
             L{CommonHomeChild} as a child of different L{CommonHome}s
         @rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
         """
-        rows = yield self._invitedFor.on(
-            self._txn, resourceID=self._resourceID
-        )
-        cls = self.__class__ # for ease of grepping...
-
-        result = []
-        for bindMode, homeResourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in rows:
-            # TODO: this could all be issued in parallel; no need to serialize
-            # the loop.
-            new = cls(
-                home=(yield self._txn.homeWithResourceID(self._home._homeType,
-                                                    homeResourceID)),
-                name=sharedResourceName, resourceID=self._resourceID,
-                owned=False, mode=bindMode, status=bindStatus, 
-                message=bindMessage, inviteUID=inviteUID,
-            )
-            yield new.initFromStore()
-
-            result.append(new)
+        result = yield self._asBound(self._invitedFor)
         returnValue(result)
 
-
     @classmethod
     @inlineCallbacks
     def loadAllObjects(cls, home, owned):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120724/56933c63/attachment.html>


More information about the calendarserver-changes mailing list