[CalendarServer-changes] [1771] CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 8 11:15:52 PDT 2007


Revision: 1771
          http://trac.macosforge.org/projects/calendarserver/changeset/1771
Author:   wsanchez at apple.com
Date:     2007-08-08 11:15:52 -0700 (Wed, 08 Aug 2007)

Log Message:
-----------
Override recordWithGUID in OD directory service to boost speed up a bit.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py

Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-08-08 17:14:23 UTC (rev 1770)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-08-08 18:15:52 UTC (rev 1771)
@@ -353,13 +353,7 @@
             DirectoryService.recordType_resources,
         )
 
-    def recordsForType(self, recordType):
-        """
-        @param recordType: a record type
-        @return: a dictionary containing all records for the given record
-        type.  Keys are short names and values are the cooresponding
-        OpenDirectoryRecord for the given record type.
-        """
+    def _storage(self, recordType):
         try:
             storage = self._records[recordType]
         except KeyError:
@@ -376,8 +370,17 @@
                 d = deferToThread(self.reloadCache, recordType)
                 d.addErrback(onError)
 
-        return self._records[recordType]["records"]
+        return storage
 
+    def recordsForType(self, recordType):
+        """
+        @param recordType: a record type
+        @return: a dictionary containing all records for the given record
+        type.  Keys are short names and values are the cooresponding
+        OpenDirectoryRecord for the given record type.
+        """
+        self._storage(recordType)["records"]
+
     def listRecords(self, recordType):
         return self.recordsForType(recordType).itervalues()
 
@@ -390,6 +393,26 @@
             self.reloadCache(recordType, shortName)
             return self.recordsForType(recordType).get(shortName, None)
 
+    def recordWithGUID(self, guid):
+        #
+        # Override super's implementation with something faster.
+        #
+        for recordType in self.recordTypes():
+            storage = self._storage(recordType)
+
+            try:
+                guidCache = storage["guids"]
+            except KeyError:
+                guidCache = {}
+                for record in storage["records"]:
+                    guidCache[record.guid] = record
+                storage["guids"] = guidCache
+
+            if guid in guidCache:
+                return guidCache[guid]
+
+        return None
+
     def reloadCache(self, recordType, shortName=None):
         log.msg("Reloading %s record cache" % (recordType,))
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070808/45c8d9e8/attachment.html


More information about the calendarserver-changes mailing list