[CalendarServer-changes] [5701] CalendarServer/branches/users/cdaboo/ cached-subscription-calendars-5692/twistedcaldav/static.py
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jun 8 12:56:38 PDT 2010
Revision: 5701
http://trac.macosforge.org/projects/calendarserver/changeset/5701
Author: cdaboo at apple.com
Date: 2010-06-08 12:56:35 -0700 (Tue, 08 Jun 2010)
Log Message:
-----------
Cached internet subscriptions.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692/twistedcaldav/static.py
Modified: CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692/twistedcaldav/static.py 2010-06-08 19:55:55 UTC (rev 5700)
+++ CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692/twistedcaldav/static.py 2010-06-08 19:56:35 UTC (rev 5701)
@@ -284,13 +284,46 @@
@inlineCallbacks
def iCalendarRolledup(self, request):
if self.isPseudoCalendarCollection():
+
+ # Determine the cache key
+ isvirt = (yield self.isVirtualShare(request))
+ if isvirt:
+ principal = (yield self.resourceOwnerPrincipal(request))
+ if principal:
+ cacheKey = principal.principalUID()
+ else:
+ cacheKey = "unknown"
+ else:
+ isowner = (yield self.isOwner(request, adminprincipals=True, readprincipals=True))
+ cacheKey = "owner" if isowner else "notowner"
+
+ # Now check for a cached .ics
+ rolled = self.fp.child(".subscriptions")
+ if not rolled.exists():
+ try:
+ rolled.makedirs()
+ except IOError, e:
+ log.err("Unable to create internet calendar subscription cache directory: %s because of: %s" % (rolled.path, e,))
+ raise HTTPError(ErrorResponse(responsecode.INTERNAL_SERVER_ERROR))
+ cached = rolled.child(cacheKey)
+ if cached.exists():
+ try:
+ cachedData = cached.open().read()
+ except IOError, e:
+ log.err("Unable to open or read internet calendar subscription cache file: %s because of: %s" % (cached.path, e,))
+ else:
+ # Check the cache token
+ token, data = cachedData.split("\r\n", 1)
+ if token == self.getSyncToken():
+ returnValue(data)
+
# Generate a monolithic calendar
calendar = iComponent("VCALENDAR")
calendar.addProperty(iProperty("VERSION", "2.0"))
# Do some optimisation of access control calculation by determining any inherited ACLs outside of
# the child resource loop and supply those to the checkPrivileges on each child.
- filteredaces = yield self.inheritedACEsforChildren(request)
+ filteredaces = (yield self.inheritedACEsforChildren(request))
tzids = set()
isowner = (yield self.isOwner(request, adminprincipals=True, readprincipals=True))
@@ -329,6 +362,14 @@
calendar.addComponent(component)
+ # Cache the data
+ data = str(calendar)
+ data = self.getSyncToken() + "\r\n" + data
+ try:
+ cached.open(mode='w').write(data)
+ except IOError, e:
+ log.err("Unable to open or write internet calendar subscription cache file: %s because of: %s" % (cached.path, e,))
+
returnValue(calendar)
raise HTTPError(ErrorResponse(responsecode.BAD_REQUEST))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100608/bf281e70/attachment.html>
More information about the calendarserver-changes
mailing list