[CalendarServer-changes] [9710] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 14 20:38:13 PDT 2012
Revision: 9710
http://trac.macosforge.org/projects/calendarserver/changeset/9710
Author: cdaboo at apple.com
Date: 2012-08-14 20:38:13 -0700 (Tue, 14 Aug 2012)
Log Message:
-----------
Optimize PUT to remove query result rows scaling with size of calendar.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/extensions.py
CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py
CalendarServer/trunk/twistedcaldav/method/put_common.py
CalendarServer/trunk/twistedcaldav/storebridge.py
CalendarServer/trunk/txdav/caldav/datastore/test/common.py
CalendarServer/trunk/txdav/common/datastore/file.py
CalendarServer/trunk/txdav/common/datastore/sql.py
Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/extensions.py 2012-08-14 22:20:32 UTC (rev 9709)
+++ CalendarServer/trunk/twistedcaldav/extensions.py 2012-08-15 03:38:13 UTC (rev 9710)
@@ -650,6 +650,13 @@
return self.putChildren.keys()
+ def countChildren(self):
+ """
+ @return: the number of all known children of this resource.
+ """
+ return len(self.putChildren.keys())
+
+
def locateChild(self, req, segments):
"""
See L{IResource.locateChild}.
Modified: CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py 2012-08-14 22:20:32 UTC (rev 9709)
+++ CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py 2012-08-15 03:38:13 UTC (rev 9710)
@@ -288,7 +288,7 @@
message = ""
if not self.destination.exists() and \
config.MaxResourcesPerCollection and \
- len((yield self.destinationparent.listChildren())) >= config.MaxResourcesPerCollection:
+ (yield self.destinationparent.countChildren()) >= config.MaxResourcesPerCollection:
result = False
message = "Too many resources in collection %s" % (self.destinationparent,)
Modified: CalendarServer/trunk/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_common.py 2012-08-14 22:20:32 UTC (rev 9709)
+++ CalendarServer/trunk/twistedcaldav/method/put_common.py 2012-08-15 03:38:13 UTC (rev 9710)
@@ -502,7 +502,7 @@
message = ""
if not self.destination.exists() and \
config.MaxResourcesPerCollection and \
- len((yield self.destinationparent.listChildren())) >= config.MaxResourcesPerCollection:
+ (yield self.destinationparent.countChildren()) >= config.MaxResourcesPerCollection:
result = False
message = "Too many resources in collection %s" % (self.destinationparent,)
Modified: CalendarServer/trunk/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/storebridge.py 2012-08-14 22:20:32 UTC (rev 9709)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py 2012-08-15 03:38:13 UTC (rev 9710)
@@ -319,6 +319,12 @@
children.update((yield self._newStoreObject.listObjectResources()))
returnValue(sorted(children))
+ def countChildren(self):
+ """
+ @return: L{Deferred} with the count of all known children of this resource.
+ """
+ return self._newStoreObject.countObjectResources()
+
def name(self):
return self._name
Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py 2012-08-14 22:20:32 UTC (rev 9709)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py 2012-08-15 03:38:13 UTC (rev 9710)
@@ -232,7 +232,7 @@
)
@classproperty(cache=False)
- def requirements(cls):
+ def requirements(cls): #@NoSelf
metadata1 = cls.metadata1.copy()
metadata2 = cls.metadata2.copy()
metadata3 = cls.metadata3.copy()
Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py 2012-08-14 22:20:32 UTC (rev 9709)
+++ CalendarServer/trunk/txdav/common/datastore/file.py 2012-08-15 03:38:13 UTC (rev 9710)
@@ -828,6 +828,10 @@
)
+ def countObjectResources(self):
+ return len(self.listObjectResources())
+
+
def objectResourceWithName(self, name):
if name in self._removedObjectResources:
return None
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2012-08-14 22:20:32 UTC (rev 9709)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2012-08-15 03:38:13 UTC (rev 9710)
@@ -70,7 +70,7 @@
from twext.enterprise.dal.syntax import \
Delete, utcNowSQL, Union, Insert, Len, Max, Parameter, SavepointAction, \
- Select, Update, ColumnSyntax, TableSyntax, Upper
+ Select, Update, ColumnSyntax, TableSyntax, Upper, Count, ALL_COLUMNS
from twistedcaldav.config import config
@@ -2253,7 +2253,7 @@
@classproperty
- def _bindEntriesFor(cls):
+ def _bindEntriesFor(cls): #@NoSelf
bind = cls._bindSchema
return Select([bind.BIND_MODE, bind.HOME_RESOURCE_ID,
bind.RESOURCE_NAME],
@@ -2489,7 +2489,7 @@
@classproperty
- def _bindInsertQuery(cls, **kw):
+ def _bindInsertQuery(cls, **kw): #@NoSelf
"""
DAL statement to create a bind entry that connects a collection to its
owner's home.
@@ -2792,6 +2792,25 @@
returnValue(self._objectNames)
+ @classproperty
+ def _objectCountQuery(cls): #@NoSelf
+ """
+ DAL query to count all object resources for a home child.
+ """
+ obj = cls._objectSchema
+ return Select([Count(ALL_COLUMNS)], From=obj,
+ Where=obj.PARENT_RESOURCE_ID == Parameter('resourceID'))
+
+
+ @inlineCallbacks
+ def countObjectResources(self):
+ if self._objectNames is None:
+ rows = yield self._objectCountQuery.on(
+ self._txn, resourceID=self._resourceID)
+ returnValue(rows[0][0])
+ returnValue(len(self._objectNames))
+
+
def objectResourceWithName(self, name):
if name in self._objects:
return succeed(self._objects[name])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120814/649faadd/attachment-0001.html>
More information about the calendarserver-changes
mailing list