[CalendarServer-changes] [13830] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 4 11:07:35 PDT 2014
Revision: 13830
http://trac.calendarserver.org//changeset/13830
Author: sagen at apple.com
Date: 2014-08-04 11:07:35 -0700 (Mon, 04 Aug 2014)
Log Message:
-----------
Fix recordsMatching*() when caching
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/extensions.py
CalendarServer/trunk/txdav/who/cache.py
CalendarServer/trunk/txdav/who/directory.py
CalendarServer/trunk/txdav/who/test/test_cache.py
Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/extensions.py 2014-08-04 16:49:31 UTC (rev 13829)
+++ CalendarServer/trunk/twistedcaldav/extensions.py 2014-08-04 18:07:35 UTC (rev 13830)
@@ -66,8 +66,11 @@
from twistedcaldav.method.report import http_REPORT
from twistedcaldav.config import config
+from txdav.who.directory import CalendarDirectoryRecordMixin
from twext.who.expression import Operand, MatchType, MatchFlags
+
+
thisModule = getModule(__name__)
log = Logger()
@@ -218,11 +221,19 @@
# nonDirectorySearches are ignored
if fields:
- records = (yield dir.recordsMatchingFieldsWithCUType(
- fields,
- operand=operand, cuType=cuType
- ))
+ if cuType:
+ recordType = CalendarDirectoryRecordMixin.fromCUType(cuType)
+ else:
+ recordType = None
+ records = (
+ yield dir.recordsMatchingFields(
+ fields,
+ operand=operand,
+ recordType=recordType
+ )
+ )
+
for record in records:
resource = yield principalCollection.principalForRecord(record)
if resource:
Modified: CalendarServer/trunk/txdav/who/cache.py
===================================================================
--- CalendarServer/trunk/txdav/who/cache.py 2014-08-04 16:49:31 UTC (rev 13829)
+++ CalendarServer/trunk/txdav/who/cache.py 2014-08-04 18:07:35 UTC (rev 13830)
@@ -317,20 +317,22 @@
return self._directory.recordsWithRecordType(recordType)
- def recordsMatchingTokens(self, *args, **kwds):
- return CalendarDirectoryServiceMixin.recordsMatchingTokens(
- self, *args, **kwds
+ def recordsMatchingTokens(self, tokens, context=None, limitResults=50,
+ timeoutSeconds=10):
+ return self._directory.recordsMatchingTokens(
+ tokens, context=context, limitResults=limitResults,
+ timeoutSeconds=timeoutSeconds
)
- def recordsMatchingFields(self, *args, **kwds):
- return CalendarDirectoryServiceMixin.recordsMatchingFields(
- self, *args, **kwds
+ def recordsMatchingFields(self, fields, operand, recordType):
+ return self._directory.recordsMatchingFields(
+ fields, operand, recordType
)
- def recordWithCalendarUserAddress(self, *args, **kwds):
+ def recordWithCalendarUserAddress(self, cua):
# This will get cached by the underlying recordWith... call
return CalendarDirectoryServiceMixin.recordWithCalendarUserAddress(
- self, *args, **kwds
+ self, cua
)
Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py 2014-08-04 16:49:31 UTC (rev 13829)
+++ CalendarServer/trunk/txdav/who/directory.py 2014-08-04 18:07:35 UTC (rev 13830)
@@ -191,18 +191,6 @@
returnValue(results)
- def recordsMatchingFieldsWithCUType(self, fields, operand=Operand.OR,
- cuType=None):
- if cuType:
- recordType = CalendarDirectoryRecordMixin.fromCUType(cuType)
- else:
- recordType = None
-
- return self.recordsMatchingFields(
- fields, operand=operand, recordType=recordType
- )
-
-
def recordsMatchingFields(self, fields, operand=Operand.OR, recordType=None):
"""
@param fields: a iterable of tuples, each tuple consisting of:
Modified: CalendarServer/trunk/txdav/who/test/test_cache.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_cache.py 2014-08-04 16:49:31 UTC (rev 13829)
+++ CalendarServer/trunk/txdav/who/test/test_cache.py 2014-08-04 18:07:35 UTC (rev 13830)
@@ -164,6 +164,36 @@
@inlineCallbacks
+ def test_cachingByCUA(self):
+ """
+ recordWithCalendarUserAddress does not cache directly; the
+ underlying recordWith...() call should do the caching instead.
+ """
+
+ dir = self.cachingDirectory
+
+ record = yield dir.recordWithCalendarUserAddress(u"mailto:cache-user-2 at example.com")
+ self.assertEquals(record.uid, u"cache-uid-2")
+ self.assertEquals(dir._hitCount, 0)
+ self.assertEquals(dir._requestCount, 1)
+ record = yield dir.recordWithCalendarUserAddress(u"mailto:cache-user-2 at example.com")
+ self.assertEquals(record.uid, u"cache-uid-2")
+ self.assertEquals(dir._hitCount, 1)
+ self.assertEquals(dir._requestCount, 2)
+
+ dir.resetCache()
+
+ record = yield dir.recordWithCalendarUserAddress(u"urn:x-uid:cache-uid-1")
+ self.assertEquals(record.uid, u"cache-uid-1")
+ self.assertEquals(dir._hitCount, 0)
+ self.assertEquals(dir._requestCount, 1)
+ record = yield dir.recordWithCalendarUserAddress(u"urn:x-uid:cache-uid-1")
+ self.assertEquals(record.uid, u"cache-uid-1")
+ self.assertEquals(dir._hitCount, 1)
+ self.assertEquals(dir._requestCount, 2)
+
+
+ @inlineCallbacks
def test_cachingExpiration(self):
"""
Verify records expire at the expected time; in these tests, 10 seconds
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140804/3309c026/attachment-0001.html>
More information about the calendarserver-changes
mailing list