[CalendarServer-changes] [13611] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 5 20:40:33 PDT 2014


Revision: 13611
          http://trac.calendarserver.org//changeset/13611
Author:   sagen at apple.com
Date:     2014-06-05 20:40:33 -0700 (Thu, 05 Jun 2014)
Log Message:
-----------
Break recordsMatchingTokens queries up by recordType because twext.who.opendirectory can't cope

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/resources.py
    CalendarServer/trunk/requirements-stable.txt
    CalendarServer/trunk/txdav/who/directory.py
    CalendarServer/trunk/txdav/who/opendirectory.py

Modified: CalendarServer/trunk/calendarserver/tools/resources.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/resources.py	2014-06-06 03:39:32 UTC (rev 13610)
+++ CalendarServer/trunk/calendarserver/tools/resources.py	2014-06-06 03:40:33 UTC (rev 13611)
@@ -31,7 +31,7 @@
 from twisted.internet.defer import inlineCallbacks, returnValue
 from txdav.who.directory import CalendarDirectoryRecordMixin
 from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
-from txdav.who.opendirectory import RecordType
+from txdav.who.idirectory import RecordType
 
 
 log = Logger()
@@ -42,7 +42,7 @@
     @inlineCallbacks
     def doWork(self):
         try:
-            from twext.who.opendirectory import (
+            from txdav.who.opendirectory import (
                 DirectoryService as OpenDirectoryService
             )
         except ImportError:
@@ -115,8 +115,8 @@
     destRecords = []
 
     for recordType in (
-        sourceService.recordType.resource,
-        sourceService.recordType.location,
+        RecordType.resource,
+        RecordType.location,
     ):
         records = yield sourceService.recordsWithRecordType(recordType)
         for sourceRecord in records:

Modified: CalendarServer/trunk/requirements-stable.txt
===================================================================
--- CalendarServer/trunk/requirements-stable.txt	2014-06-06 03:39:32 UTC (rev 13610)
+++ CalendarServer/trunk/requirements-stable.txt	2014-06-06 03:40:33 UTC (rev 13611)
@@ -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@13604#egg=twextpy
+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13610#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@13576#egg=pycalendar
 

Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py	2014-06-06 03:39:32 UTC (rev 13610)
+++ CalendarServer/trunk/txdav/who/directory.py	2014-06-06 03:40:33 UTC (rev 13611)
@@ -143,6 +143,7 @@
         return recordTypes
 
 
+    @inlineCallbacks
     def recordsMatchingTokens(self, tokens, context=None, limitResults=50,
                               timeoutSeconds=10):
         fields = [
@@ -174,37 +175,45 @@
         else:
             expression = CompoundExpression(outer, Operand.AND)
 
+        results = []
+
         if context is not None:
+            # We're limiting record types, so for each recordType, build a
+            # CompoundExpression that ANDs the original expression with a
+            # typeSpecific one.  Collect all the results from these expressions.
             recordTypes = self.recordTypesForSearchContext(context)
-            log.debug("Context {c}, recordTypes {r}", c=context, r=recordTypes)
-            typeSpecific = []
+            log.debug("Tokens: {t}, recordTypes {r}", t=tokens, r=recordTypes)
             for recordType in recordTypes:
-                typeSpecific.append(
-                    MatchExpression(
-                        self.fieldName.recordType,
-                        recordType,
-                        MatchType.equals,
-                        MatchFlags.none
-                    )
+                typeSpecific = MatchExpression(
+                    self.fieldName.recordType,
+                    recordType,
+                    MatchType.equals,
+                    MatchFlags.none
                 )
 
-            if len(typeSpecific) == 1:
-                typeSpecific = typeSpecific[0]
-
-            else:
                 typeSpecific = CompoundExpression(
-                    typeSpecific,
-                    Operand.OR
+                    [expression, typeSpecific],
+                    Operand.AND
                 )
 
-            expression = CompoundExpression(
-                [expression, typeSpecific],
-                Operand.AND
+                subResults = yield self.recordsFromExpression(typeSpecific)
+                log.debug(
+                    "Tokens ({t}) matched {n} of {r}",
+                    t=tokens, n=len(subResults), r=recordType
+                )
+                results.extend(subResults)
+
+        else:
+            # No record type limits
+            results = yield self.recordsFromExpression(expression)
+            log.debug(
+                "Tokens ({t}) matched {n} records",
+                t=tokens, n=len(results)
             )
 
-        log.debug("Expression {e}", e=expression)
+        log.debug("Tokens ({t}) matched records {r}", t=tokens, r=results)
 
-        return self.recordsFromExpression(expression)
+        returnValue(results)
 
 
     def recordsMatchingFieldsWithCUType(self, fields, operand=Operand.OR,

Modified: CalendarServer/trunk/txdav/who/opendirectory.py
===================================================================
--- CalendarServer/trunk/txdav/who/opendirectory.py	2014-06-06 03:39:32 UTC (rev 13610)
+++ CalendarServer/trunk/txdav/who/opendirectory.py	2014-06-06 03:40:33 UTC (rev 13611)
@@ -24,32 +24,14 @@
 
 __all__ = [
     "DirectoryService",
-    "RecordType"
 ]
 
 from twext.who.opendirectory import DirectoryService
-from twisted.python.constants import Names, NamedConstant
 
 
-
 # Hoorj OMG haxx
 from twext.who.opendirectory._constants import ODRecordType as _ODRecordType
 from .idirectory import RecordType as _CSRecordType
 
 _ODRecordType.location.recordType = _CSRecordType.location
 _ODRecordType.resource.recordType = _CSRecordType.resource
-
-
-class RecordType(Names):
-
-    user = NamedConstant()
-    user.description = u"user"
-
-    group = NamedConstant()
-    group.description = u"group"
-
-    location = NamedConstant()
-    location.description = u"location"
-
-    resource = NamedConstant()
-    resource.description = u"resource"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140605/ed90f673/attachment-0001.html>


More information about the calendarserver-changes mailing list