[CalendarServer-changes] [13949] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Sep 10 20:34:30 PDT 2014


Revision: 13949
          http://trac.calendarserver.org//changeset/13949
Author:   sagen at apple.com
Date:     2014-09-10 20:34:30 -0700 (Wed, 10 Sep 2014)
Log Message:
-----------
Adds support for limiting directory results and timeouts

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/requirements-stable.txt
    CalendarServer/trunk/twistedcaldav/extensions.py
    CalendarServer/trunk/txdav/dps/client.py
    CalendarServer/trunk/txdav/dps/commands.py
    CalendarServer/trunk/txdav/dps/server.py
    CalendarServer/trunk/txdav/who/augment.py
    CalendarServer/trunk/txdav/who/cache.py
    CalendarServer/trunk/txdav/who/delegates.py
    CalendarServer/trunk/txdav/who/directory.py
    CalendarServer/trunk/txdav/who/test/test_group_attendees.py
    CalendarServer/trunk/txdav/who/wiki.py

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -523,6 +523,11 @@
 @inlineCallbacks
 def action_listProxyFor(store, record, *proxyTypes):
     directory = store.directoryService()
+
+    if record.recordType != directory.recordType.user:
+        print("You must pass a user principal to this command")
+        returnValue(None)
+
     for proxyType in proxyTypes:
 
         groupRecordType = {

Modified: CalendarServer/trunk/requirements-stable.txt
===================================================================
--- CalendarServer/trunk/requirements-stable.txt	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/requirements-stable.txt	2014-09-11 03:34:30 UTC (rev 13949)
@@ -5,7 +5,7 @@
 # For CalendarServer development, don't try to get these projects from PyPI; use svn.
 
 -e .
--e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13938#egg=twextpy
+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13948#egg=twextpy
 -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
 -e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13802#egg=pycalendar
 

Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/extensions.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/twistedcaldav/extensions.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -230,7 +230,9 @@
                 yield dir.recordsMatchingFields(
                     fields,
                     operand=operand,
-                    recordType=recordType
+                    recordType=recordType,
+                    limitResults=clientLimit,
+                    timeoutSeconds=10
                 )
             )
 
@@ -329,7 +331,12 @@
         matchingResources = []
         matchcount = 0
 
-        records = (yield dir.recordsMatchingTokens(tokens, context=context))
+        records = (yield dir.recordsMatchingTokens(
+            tokens,
+            context=context,
+            limitResults=clientLimit,
+            timeoutSeconds=10
+        ))
 
         for record in records:
             resource = yield principalCollection.principalForRecord(record)

Modified: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/client.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/dps/client.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -242,7 +242,7 @@
         returnValue(postProcess(results))
 
 
-    def recordWithShortName(self, recordType, shortName):
+    def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
         # MOVE2WHO
         # temporary hack until we can fix all callers not to pass strings:
         if isinstance(recordType, (str, unicode)):
@@ -253,64 +253,110 @@
             # log.warn("Need to change shortName to unicode")
             shortName = shortName.decode("utf-8")
 
+        kwds = {
+            "recordType": recordType.name.encode("utf-8"),
+            "shortName": shortName.encode("utf-8")
+        }
+        if timeoutSeconds is not None:
+            kwds["timeoutSeconds"] = timeoutSeconds
+
         return self._call(
             RecordWithShortNameCommand,
             self._processSingleRecord,
-            recordType=recordType.name.encode("utf-8"),
-            shortName=shortName.encode("utf-8")
+            **kwds
         )
 
 
-    def recordWithUID(self, uid):
+    def recordWithUID(self, uid, timeoutSeconds=None):
         # MOVE2WHO, REMOVE THIS:
         if not isinstance(uid, unicode):
             # log.warn("Need to change uid to unicode")
             uid = uid.decode("utf-8")
 
+        kwds = {
+            "uid": uid.encode("utf-8"),
+        }
+        if timeoutSeconds is not None:
+            kwds["timeoutSeconds"] = timeoutSeconds
+
         return self._call(
             RecordWithUIDCommand,
             self._processSingleRecord,
-            uid=uid.encode("utf-8")
+            **kwds
         )
 
 
-    def recordWithGUID(self, guid):
+    def recordWithGUID(self, guid, timeoutSeconds=None):
+        kwds = {
+            "guid": str(guid),
+        }
+        if timeoutSeconds is not None:
+            kwds["timeoutSeconds"] = timeoutSeconds
+
         return self._call(
             RecordWithGUIDCommand,
             self._processSingleRecord,
-            guid=str(guid)
+            **kwds
         )
 
 
-    def recordsWithRecordType(self, recordType):
+    def recordsWithRecordType(
+        self, recordType, limitResults=None, timeoutSeconds=None
+    ):
+        kwds = {
+            "recordType": recordType.name.encode("utf-8")
+        }
+        if limitResults is not None:
+            kwds["limitResults"] = limitResults
+        if timeoutSeconds is not None:
+            kwds["timeoutSeconds"] = timeoutSeconds
         return self._call(
             RecordsWithRecordTypeCommand,
             self._processMultipleRecords,
-            recordType=recordType.name.encode("utf-8")
+            **kwds
         )
 
 
-    def recordsWithEmailAddress(self, emailAddress):
+    def recordsWithEmailAddress(
+        self, emailAddress, limitResults=None, timeoutSeconds=None
+    ):
+        kwds = {
+            "emailAddress": emailAddress.encode("utf-8")
+        }
+        if limitResults is not None:
+            kwds["limitResults"] = limitResults
+        if timeoutSeconds is not None:
+            kwds["timeoutSeconds"] = timeoutSeconds
+
         return self._call(
             RecordsWithEmailAddressCommand,
             self._processMultipleRecords,
-            emailAddress=emailAddress.encode("utf-8")
+            **kwds
         )
 
 
     def recordsMatchingTokens(
-        self, tokens, context=None, limitResults=50, timeoutSeconds=10
+        self, tokens, context=None, limitResults=None, timeoutSeconds=None
     ):
+        kwds = {
+            "tokens": [t.encode("utf-8") for t in tokens],
+            "context": context
+        }
+        if limitResults is not None:
+            kwds["limitResults"] = limitResults
+        if timeoutSeconds is not None:
+            kwds["timeoutSeconds"] = timeoutSeconds
+
         return self._call(
             RecordsMatchingTokensCommand,
             self._processMultipleRecords,
-            tokens=[t.encode("utf-8") for t in tokens],
-            context=context
+            **kwds
         )
 
 
     def recordsMatchingFields(
-        self, fields, operand=Operand.OR, recordType=None
+        self, fields, operand=Operand.OR, recordType=None,
+        limitResults=None, timeoutSeconds=None
     ):
         newFields = []
         for fieldName, searchTerm, matchFlags, matchType in fields:
@@ -329,12 +375,21 @@
         if recordType is not None:
             recordType = recordType.name.encode("utf-8")
 
+        kwds = {
+            "fields": newFields,
+            "operand": operand.name.encode("utf-8"),
+            "recordType": recordType
+        }
+        if limitResults is not None:
+            kwds["limitResults"] = limitResults
+        if timeoutSeconds is not None:
+            kwds["timeoutSeconds"] = timeoutSeconds
+
+
         return self._call(
             RecordsMatchingFieldsCommand,
             self._processMultipleRecords,
-            fields=newFields,
-            operand=operand.name.encode("utf-8"),
-            recordType=recordType
+            **kwds
         )
 
 

Modified: CalendarServer/trunk/txdav/dps/commands.py
===================================================================
--- CalendarServer/trunk/txdav/dps/commands.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/dps/commands.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -21,6 +21,7 @@
     arguments = [
         ('recordType', amp.String()),
         ('shortName', amp.String()),
+        ('timeoutSeconds', amp.Integer(optional=True)),
     ]
     response = [
         ('fields', amp.String()),
@@ -31,6 +32,7 @@
 class RecordWithUIDCommand(amp.Command):
     arguments = [
         ('uid', amp.String()),
+        ('timeoutSeconds', amp.Integer(optional=True)),
     ]
     response = [
         ('fields', amp.String()),
@@ -41,6 +43,7 @@
 class RecordWithGUIDCommand(amp.Command):
     arguments = [
         ('guid', amp.String()),
+        ('timeoutSeconds', amp.Integer(optional=True)),
     ]
     response = [
         ('fields', amp.String()),
@@ -51,6 +54,8 @@
 class RecordsWithRecordTypeCommand(amp.Command):
     arguments = [
         ('recordType', amp.String()),
+        ('limitResults', amp.Integer(optional=True)),
+        ('timeoutSeconds', amp.Integer(optional=True)),
     ]
     response = [
         ('items', amp.ListOf(amp.String())),
@@ -62,6 +67,8 @@
 class RecordsWithEmailAddressCommand(amp.Command):
     arguments = [
         ('emailAddress', amp.String()),
+        ('limitResults', amp.Integer(optional=True)),
+        ('timeoutSeconds', amp.Integer(optional=True)),
     ]
     response = [
         ('items', amp.ListOf(amp.String())),
@@ -85,6 +92,8 @@
     arguments = [
         ('tokens', amp.ListOf(amp.String())),
         ('context', amp.String(optional=True)),
+        ('limitResults', amp.Integer(optional=True)),
+        ('timeoutSeconds', amp.Integer(optional=True)),
     ]
     response = [
         ('items', amp.ListOf(amp.String())),
@@ -98,6 +107,8 @@
         ('fields', amp.ListOf(amp.ListOf(amp.String()))),
         ('operand', amp.String()),
         ('recordType', amp.String(optional=True)),
+        ('limitResults', amp.Integer(optional=True)),
+        ('timeoutSeconds', amp.Integer(optional=True)),
     ]
     response = [
         ('items', amp.ListOf(amp.String())),

Modified: CalendarServer/trunk/txdav/dps/server.py
===================================================================
--- CalendarServer/trunk/txdav/dps/server.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/dps/server.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -228,13 +228,14 @@
 
     @RecordWithShortNameCommand.responder
     @inlineCallbacks
-    def recordWithShortName(self, recordType, shortName):
+    def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
         recordType = recordType  # keep as bytes
         shortName = shortName.decode("utf-8")
         log.debug("RecordWithShortName: {r} {n}", r=recordType, n=shortName)
         record = (yield self._directory.recordWithShortName(
-            self._directory.recordType.lookupByName(recordType), shortName)
-        )
+            self._directory.recordType.lookupByName(recordType), shortName,
+            timeoutSeconds=timeoutSeconds
+        ))
         fields = self.recordToDict(record)
         response = {
             "fields": pickle.dumps(fields),
@@ -245,11 +246,13 @@
 
     @RecordWithUIDCommand.responder
     @inlineCallbacks
-    def recordWithUID(self, uid):
+    def recordWithUID(self, uid, timeoutSeconds=None):
         uid = uid.decode("utf-8")
         log.debug("RecordWithUID: {u}", u=uid)
         try:
-            record = (yield self._directory.recordWithUID(uid))
+            record = (yield self._directory.recordWithUID(
+                uid, timeoutSeconds=timeoutSeconds
+            ))
         except Exception as e:
             log.error("Failed in recordWithUID", error=e)
             record = None
@@ -263,10 +266,12 @@
 
     @RecordWithGUIDCommand.responder
     @inlineCallbacks
-    def recordWithGUID(self, guid):
+    def recordWithGUID(self, guid, timeoutSeconds=None):
         guid = uuid.UUID(guid)
         log.debug("RecordWithGUID: {g}", g=guid)
-        record = (yield self._directory.recordWithGUID(guid))
+        record = (yield self._directory.recordWithGUID(
+            guid, timeoutSeconds=timeoutSeconds
+        ))
         fields = self.recordToDict(record)
         response = {
             "fields": pickle.dumps(fields),
@@ -277,12 +282,15 @@
 
     @RecordsWithRecordTypeCommand.responder
     @inlineCallbacks
-    def recordsWithRecordType(self, recordType):
+    def recordsWithRecordType(
+        self, recordType, limitResults=None, timeoutSeconds=None
+    ):
         recordType = recordType  # as bytes
         log.debug("RecordsWithRecordType: {r}", r=recordType)
         records = (yield self._directory.recordsWithRecordType(
-            self._directory.recordType.lookupByName(recordType))
-        )
+            self._directory.recordType.lookupByName(recordType),
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
+        ))
         response = self._recordsToResponse(records)
         # log.debug("Responding with: {response}", response=response)
         returnValue(response)
@@ -290,10 +298,15 @@
 
     @RecordsWithEmailAddressCommand.responder
     @inlineCallbacks
-    def recordsWithEmailAddress(self, emailAddress):
+    def recordsWithEmailAddress(
+        self, emailAddress, limitResults=None, timeoutSeconds=None
+    ):
         emailAddress = emailAddress.decode("utf-8")
         log.debug("RecordsWithEmailAddress: {e}", e=emailAddress)
-        records = (yield self._directory.recordsWithEmailAddress(emailAddress))
+        records = (yield self._directory.recordsWithEmailAddress(
+            emailAddress,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
+        ))
         response = self._recordsToResponse(records)
         # log.debug("Responding with: {response}", response=response)
         returnValue(response)
@@ -301,11 +314,14 @@
 
     @RecordsMatchingTokensCommand.responder
     @inlineCallbacks
-    def recordsMatchingTokens(self, tokens, context=None):
+    def recordsMatchingTokens(
+        self, tokens, context=None, limitResults=None, timeoutSeconds=None
+    ):
         tokens = [t.decode("utf-8") for t in tokens]
         log.debug("RecordsMatchingTokens: {t}", t=(", ".join(tokens)))
         records = yield self._directory.recordsMatchingTokens(
-            tokens, context=context
+            tokens, context=context,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
         response = self._recordsToResponse(records)
         # log.debug("Responding with: {response}", response=response)
@@ -314,7 +330,10 @@
 
     @RecordsMatchingFieldsCommand.responder
     @inlineCallbacks
-    def recordsMatchingFields(self, fields, operand="OR", recordType=None):
+    def recordsMatchingFields(
+        self, fields, operand="OR", recordType=None,
+        limitResults=None, timeoutSeconds=None
+    ):
         log.debug("RecordsMatchingFields")
         newFields = []
         for fieldName, searchTerm, matchFlags, matchType in fields:
@@ -345,7 +364,8 @@
         if recordType:
             recordType = self._directory.recordType.lookupByName(recordType)
         records = yield self._directory.recordsMatchingFields(
-            newFields, operand=operand, recordType=recordType
+            newFields, operand=operand, recordType=recordType,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
         response = self._recordsToResponse(records)
         # log.debug("Responding with: {response}", response=response)

Modified: CalendarServer/trunk/txdav/who/augment.py
===================================================================
--- CalendarServer/trunk/txdav/who/augment.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/who/augment.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -151,9 +151,13 @@
 
 
     @inlineCallbacks
-    def recordsFromExpression(self, expression, recordTypes=None):
+    def recordsFromExpression(
+        self, expression, recordTypes=None,
+        limitResults=None, timeoutSeconds=None
+    ):
         records = yield self._directory.recordsFromExpression(
-            expression, recordTypes=recordTypes
+            expression, recordTypes=recordTypes,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
         augmented = []
         for record in records:
@@ -163,9 +167,12 @@
 
 
     @inlineCallbacks
-    def recordsWithFieldValue(self, fieldName, value):
+    def recordsWithFieldValue(
+        self, fieldName, value, limitResults=None, timeoutSeconds=None
+    ):
         records = yield self._directory.recordsWithFieldValue(
-            fieldName, value
+            fieldName, value,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
         augmented = []
         for record in records:
@@ -176,29 +183,37 @@
 
     @timed
     @inlineCallbacks
-    def recordWithUID(self, uid):
+    def recordWithUID(self, uid, timeoutSeconds=None):
         # MOVE2WHO, REMOVE THIS:
         if not isinstance(uid, unicode):
             # log.warn("Need to change uid to unicode")
             uid = uid.decode("utf-8")
 
-        record = yield self._directory.recordWithUID(uid)
+        record = yield self._directory.recordWithUID(
+            uid, timeoutSeconds=timeoutSeconds
+        )
         record = yield self._augment(record)
         returnValue(record)
 
 
     @timed
     @inlineCallbacks
-    def recordWithGUID(self, guid):
-        record = yield self._directory.recordWithGUID(guid)
+    def recordWithGUID(self, guid, timeoutSeconds=None):
+        record = yield self._directory.recordWithGUID(
+            guid, timeoutSeconds=timeoutSeconds
+        )
         record = yield self._augment(record)
         returnValue(record)
 
 
     @timed
     @inlineCallbacks
-    def recordsWithRecordType(self, recordType):
-        records = yield self._directory.recordsWithRecordType(recordType)
+    def recordsWithRecordType(
+        self, recordType, limitResults=None, timeoutSeconds=None
+    ):
+        records = yield self._directory.recordsWithRecordType(
+            recordType, limitResults=limitResults, timeoutSeconds=timeoutSeconds
+        )
         augmented = []
         for record in records:
             record = yield self._augment(record)
@@ -208,14 +223,14 @@
 
     @timed
     @inlineCallbacks
-    def recordWithShortName(self, recordType, shortName):
+    def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
         # MOVE2WHO, REMOVE THIS:
         if not isinstance(shortName, unicode):
             # log.warn("Need to change shortName to unicode")
             shortName = shortName.decode("utf-8")
 
         record = yield self._directory.recordWithShortName(
-            recordType, shortName
+            recordType, shortName, timeoutSeconds=timeoutSeconds
         )
         record = yield self._augment(record)
         returnValue(record)
@@ -223,13 +238,18 @@
 
     @timed
     @inlineCallbacks
-    def recordsWithEmailAddress(self, emailAddress):
+    def recordsWithEmailAddress(
+        self, emailAddress, limitResults=None, timeoutSeconds=None
+    ):
         # MOVE2WHO, REMOVE THIS:
         if not isinstance(emailAddress, unicode):
             # log.warn("Need to change emailAddress to unicode")
             emailAddress = emailAddress.decode("utf-8")
 
-        records = yield self._directory.recordsWithEmailAddress(emailAddress)
+        records = yield self._directory.recordsWithEmailAddress(
+            emailAddress,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
+        )
         augmented = []
         for record in records:
             record = yield self._augment(record)

Modified: CalendarServer/trunk/txdav/who/cache.py
===================================================================
--- CalendarServer/trunk/txdav/who/cache.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/who/cache.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -232,12 +232,14 @@
     # Cached methods:
 
     @inlineCallbacks
-    def recordWithUID(self, uid):
+    def recordWithUID(self, uid, timeoutSeconds=None):
 
         # First check our cache
         record = self.lookupRecord(IndexType.uid, uid, "recordWithUID")
         if record is None:
-            record = yield self._directory.recordWithUID(uid)
+            record = yield self._directory.recordWithUID(
+                uid, timeoutSeconds=timeoutSeconds
+            )
             if record is not None:
                 # Note we do not index on email address; see below.
                 self.cacheRecord(
@@ -249,12 +251,14 @@
 
 
     @inlineCallbacks
-    def recordWithGUID(self, guid):
+    def recordWithGUID(self, guid, timeoutSeconds=None):
 
         # First check our cache
         record = self.lookupRecord(IndexType.guid, guid, "recordWithGUID")
         if record is None:
-            record = yield self._directory.recordWithGUID(guid)
+            record = yield self._directory.recordWithGUID(
+                guid, timeoutSeconds=timeoutSeconds
+            )
             if record is not None:
                 # Note we do not index on email address; see below.
                 self.cacheRecord(
@@ -266,7 +270,7 @@
 
 
     @inlineCallbacks
-    def recordWithShortName(self, recordType, shortName):
+    def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
 
         # First check our cache
         record = self.lookupRecord(
@@ -276,7 +280,7 @@
         )
         if record is None:
             record = yield self._directory.recordWithShortName(
-                recordType, shortName
+                recordType, shortName, timeoutSeconds=timeoutSeconds
             )
             if record is not None:
                 # Note we do not index on email address; see below.
@@ -289,7 +293,9 @@
 
 
     @inlineCallbacks
-    def recordsWithEmailAddress(self, emailAddress):
+    def recordsWithEmailAddress(
+        self, emailAddress, limitResults=None, timeoutSeconds=None
+    ):
 
         # First check our cache
         record = self.lookupRecord(
@@ -298,7 +304,10 @@
             "recordsWithEmailAddress"
         )
         if record is None:
-            records = yield self._directory.recordsWithEmailAddress(emailAddress)
+            records = yield self._directory.recordsWithEmailAddress(
+                emailAddress,
+                limitResults=limitResults, timeoutSeconds=timeoutSeconds
+            )
             if len(records) == 1:
                 # Only cache if there was a single match (which is the most
                 # common scenario).  Caching multiple records for the exact
@@ -335,17 +344,25 @@
         return self._directory.recordTypes()
 
 
-    def recordsFromExpression(self, expression, recordTypes=None):
+    def recordsFromExpression(
+        self, expression, recordTypes=None,
+        limitResults=None, timeoutSeconds=None
+    ):
         # Defer to the directory service we're caching
         return self._directory.recordsFromExpression(
-            expression, recordTypes=recordTypes
+            expression, recordTypes=recordTypes,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
 
 
-    def recordsWithFieldValue(self, fieldName, value):
+    def recordsWithFieldValue(
+        self, fieldName, value,
+        limitResults=None, timeoutSeconds=None
+    ):
         # Defer to the directory service we're caching
         return self._directory.recordsWithFieldValue(
-            fieldName, value
+            fieldName, value,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
 
 
@@ -359,22 +376,31 @@
         return self._directory.removeRecords(uids)
 
 
-    def recordsWithRecordType(self, recordType):
+    def recordsWithRecordType(
+        self, recordType, limitResults=None, timeoutSeconds=None
+    ):
         # Defer to the directory service we're caching
-        return self._directory.recordsWithRecordType(recordType)
+        return self._directory.recordsWithRecordType(
+            recordType, limitResults=limitResults, timeoutSeconds=timeoutSeconds
+        )
 
 
-    def recordsMatchingTokens(self, tokens, context=None, limitResults=50,
-                              timeoutSeconds=10):
+    def recordsMatchingTokens(
+        self, tokens, context=None, limitResults=None, timeoutSeconds=None
+    ):
         return self._directory.recordsMatchingTokens(
-            tokens, context=context, limitResults=limitResults,
-            timeoutSeconds=timeoutSeconds
+            tokens, context=context,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
 
 
-    def recordsMatchingFields(self, fields, operand, recordType):
+    def recordsMatchingFields(
+        self, fields, operand, recordType,
+        limitResults=None, timeoutSeconds=None
+    ):
         return self._directory.recordsMatchingFields(
-            fields, operand, recordType
+            fields, operand, recordType,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
         )
 
 
@@ -382,10 +408,10 @@
         return self._directory.recordsWithDirectoryBasedDelegates()
 
 
-    def recordWithCalendarUserAddress(self, cua):
+    def recordWithCalendarUserAddress(self, cua, timeoutSeconds=None):
         # This will get cached by the underlying recordWith... call
         return CalendarDirectoryServiceMixin.recordWithCalendarUserAddress(
-            self, cua
+            self, cua, timeoutSeconds=timeoutSeconds
         )
 
 

Modified: CalendarServer/trunk/txdav/who/delegates.py
===================================================================
--- CalendarServer/trunk/txdav/who/delegates.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/who/delegates.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -115,7 +115,7 @@
         parentUID, _ignore_proxyType = self.uid.split(u"#")
         readWrite = (self.recordType is RecordType.writeDelegateGroup)
 
-        log.debug(
+        log.info(
             "Setting delegate assignments for {u} ({rw}) to {m}",
             u=parentUID, rw=("write" if readWrite else "read"),
             m=[r.uid for r in memberRecords]
@@ -177,7 +177,7 @@
         self._masterDirectory = masterDirectory
 
 
-    def recordWithShortName(self, recordType, shortName):
+    def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
         uid = shortName + "#" + recordTypeToProxyType(recordType)
 
         record = DirectoryRecord(self, {
@@ -188,18 +188,23 @@
         return succeed(record)
 
 
-    def recordWithUID(self, uid):
+    def recordWithUID(self, uid, timeoutSeconds=None):
         if "#" not in uid:  # Not a delegate group uid
             return succeed(None)
         uid, proxyType = uid.split("#")
         recordType = proxyTypeToRecordType(proxyType)
         if recordType is None:
             return succeed(None)
-        return self.recordWithShortName(recordType, uid)
+        return self.recordWithShortName(
+            recordType, uid, timeoutSeconds=timeoutSeconds
+        )
 
 
     @inlineCallbacks
-    def recordsFromExpression(self, expression, recordTypes=None, records=None):
+    def recordsFromExpression(
+        self, expression, recordTypes=None, records=None,
+        limitResults=None, timeoutSeconds=None
+    ):
         """
         It's only ever appropriate to look up delegate group record by
         shortName or uid.  When wrapped by an aggregate directory, looking up
@@ -213,7 +218,9 @@
                 (expression.matchType is MatchType.equals) and
                 ("#" in expression.fieldValue)
             ):
-                record = yield self.recordWithUID(expression.fieldValue)
+                record = yield self.recordWithUID(
+                    expression.fieldValue, timeoutSeconds=timeoutSeconds
+                )
                 if record is not None:
                     returnValue((record,))
 

Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/who/directory.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -71,13 +71,17 @@
 
 
     @inlineCallbacks
-    def recordWithCalendarUserAddress(self, address):
+    def recordWithCalendarUserAddress(
+        self, address, timeoutSeconds=None
+    ):
         address = normalizeCUAddr(address)
         record = None
 
         if address.startswith("urn:x-uid:"):
             uid = address[10:]
-            record = yield self.recordWithUID(uid)
+            record = yield self.recordWithUID(
+                uid, timeoutSeconds=timeoutSeconds
+            )
 
         elif address.startswith("urn:uuid:"):
             try:
@@ -85,10 +89,14 @@
             except ValueError:
                 log.info("Invalid GUID: {guid}", guid=address[9:])
                 returnValue(None)
-            record = yield self.recordWithGUID(guid)
+            record = yield self.recordWithGUID(
+                guid, timeoutSeconds=timeoutSeconds
+            )
 
         elif address.startswith("mailto:"):
-            records = yield self.recordsWithEmailAddress(address[7:])
+            records = yield self.recordsWithEmailAddress(
+                address[7:], limitResults=1, timeoutSeconds=timeoutSeconds
+            )
             record = records[0] if records else None
 
         elif address.startswith("/principals/"):
@@ -96,10 +104,14 @@
             if len(parts) == 4:
                 if parts[2] == "__uids__":
                     uid = parts[3]
-                    record = yield self.recordWithUID(uid)
+                    record = yield self.recordWithUID(
+                        uid, timeoutSeconds=timeoutSeconds
+                    )
                 else:
                     recordType = self.oldNameToRecordType(parts[2])
-                    record = yield self.recordWithShortName(recordType, parts[3])
+                    record = yield self.recordWithShortName(
+                        recordType, parts[3], timeoutSeconds=timeoutSeconds
+                    )
 
         if record:
             if record.hasCalendars or (
@@ -146,8 +158,8 @@
 
 
     @inlineCallbacks
-    def recordsMatchingTokens(self, tokens, context=None, limitResults=50,
-                              timeoutSeconds=10):
+    def recordsMatchingTokens(self, tokens, context=None, limitResults=None,
+                              timeoutSeconds=None):
         fields = [
             ("fullNames", MatchType.contains),
             ("emailAddresses", MatchType.startsWith),
@@ -183,7 +195,8 @@
             recordTypes = None
 
         results = yield self.recordsFromExpression(
-            expression, recordTypes=recordTypes
+            expression, recordTypes=recordTypes, limitResults=limitResults,
+            timeoutSeconds=timeoutSeconds
         )
         log.debug(
             "Tokens ({t}) matched {n} records",
@@ -193,7 +206,10 @@
         returnValue(results)
 
 
-    def recordsMatchingFields(self, fields, operand=Operand.OR, recordType=None):
+    def recordsMatchingFields(
+        self, fields, operand=Operand.OR, recordType=None,
+        limitResults=None, timeoutSeconds=None
+    ):
         """
         @param fields: a iterable of tuples, each tuple consisting of:
             directory field name (C{unicode})
@@ -228,7 +244,10 @@
             recordTypes = [recordType]
         else:
             recordTypes = None
-        return self.recordsFromExpression(expression, recordTypes=recordTypes)
+        return self.recordsFromExpression(
+            expression, recordTypes=recordTypes,
+            limitResults=limitResults, timeoutSeconds=timeoutSeconds
+        )
 
 
     _oldRecordTypeNames = {
@@ -282,11 +301,7 @@
 
         records = yield self.recordsFromExpression(
             expression,
-            recordTypes=(self.recordType.location,)
-            # FIXME, commenting out resources for the moment since it's
-            # super slow:
-            # recordTypes=(self.recordType.location, self.recordType.resource)
-
+            recordTypes=(self.recordType.location, self.recordType.resource)
         )
         returnValue(records)
 

Modified: CalendarServer/trunk/txdav/who/test/test_group_attendees.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -1459,7 +1459,7 @@
         unpatchedRecordWithUID = DirectoryService.recordWithUID
 
         @inlineCallbacks
-        def recordWithUID(self, uid):
+        def recordWithUID(self, uid, timeoutSeconds=None):
 
             if uid == "group02":
                 result = None

Modified: CalendarServer/trunk/txdav/who/wiki.py
===================================================================
--- CalendarServer/trunk/txdav/who/wiki.py	2014-09-11 03:32:22 UTC (rev 13948)
+++ CalendarServer/trunk/txdav/who/wiki.py	2014-09-11 03:34:30 UTC (rev 13949)
@@ -121,19 +121,22 @@
         return succeed(None)
 
 
-    def recordWithUID(self, uid):
+    def recordWithUID(self, uid, timeoutSeconds=None):
         if uid.startswith(self.uidPrefix):
             return self._recordWithName(uid[len(self.uidPrefix):])
         return succeed(None)
 
 
-    def recordWithShortName(self, recordType, shortName):
+    def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
         if recordType is RecordType.macOSXServerWiki:
             return self._recordWithName(shortName)
         return succeed(None)
 
 
-    def recordsFromExpression(self, expression, recordTypes=None, records=None):
+    def recordsFromExpression(
+        self, expression, recordTypes=None, records=None,
+        limitResults=None, timeoutSeconds=None
+    ):
         return succeed(())
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140910/dbf5957c/attachment-0001.html>


More information about the calendarserver-changes mailing list