[CalendarServer-changes] [8217] CalendarServer/trunk/twistedcaldav/upgrade.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 21 11:55:48 PDT 2011
Revision: 8217
http://trac.macosforge.org/projects/calendarserver/changeset/8217
Author: sagen at apple.com
Date: 2011-10-21 11:55:48 -0700 (Fri, 21 Oct 2011)
Log Message:
-----------
Cache the results of lookupFunction, not just the principals, to avoid the replace( ) calls.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/upgrade.py
Modified: CalendarServer/trunk/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/upgrade.py 2011-10-21 18:35:09 UTC (rev 8216)
+++ CalendarServer/trunk/twistedcaldav/upgrade.py 2011-10-21 18:55:48 UTC (rev 8217)
@@ -522,19 +522,19 @@
cal = Component.fromString(data)
def lookupFunction(cuaddr):
+
+ # Return cached results, if any.
+ if cuaCache.has_key(cuaddr):
+ return cuaCache[cuaddr]
+
try:
- if cuaCache.has_key(cuaddr):
- principal = cuaCache[cuaddr]
- else:
- principal = directory.principalForCalendarUserAddress(cuaddr)
+ principal = directory.principalForCalendarUserAddress(cuaddr)
except Exception, e:
log.debug("Lookup of %s failed: %s" % (cuaddr, e))
principal = None
- cuaCache[cuaddr] = principal
-
if principal is None:
- return (None, None, None)
+ result = (None, None, None)
else:
rec = principal.record
@@ -545,8 +545,12 @@
# to single-quotes.
fullName = rec.fullName.replace('"', "'")
- return (fullName, rec.guid, rec.calendarUserAddresses)
+ result = (fullName, rec.guid, rec.calendarUserAddresses)
+ # Cache the result
+ cuaCache[cuaddr] = result
+ return result
+
cal.normalizeCalendarUserAddresses(lookupFunction)
newData = str(cal)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111021/e589a785/attachment-0001.html>
More information about the calendarserver-changes
mailing list