[CalendarServer-changes] [1819]
CalendarServer/trunk/twistedcaldav/admin/util.py
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 21 10:41:28 PDT 2007
Revision: 1819
http://trac.macosforge.org/projects/calendarserver/changeset/1819
Author: dreid at apple.com
Date: 2007-08-21 10:41:27 -0700 (Tue, 21 Aug 2007)
Log Message:
-----------
Count events and todos from the SQL Database instead of by parsing all events.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/admin/util.py
Modified: CalendarServer/trunk/twistedcaldav/admin/util.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/admin/util.py 2007-08-21 17:25:21 UTC (rev 1818)
+++ CalendarServer/trunk/twistedcaldav/admin/util.py 2007-08-21 17:41:27 UTC (rev 1819)
@@ -23,7 +23,8 @@
from twisted.web import microdom
from twistedcaldav import ical
-from twistedcaldav.sql import db_prefix
+from twistedcaldav.sql import db_prefix, AbstractSQLDatabase
+from twistedcaldav.index import schema_version, collection_types
def prepareByteValue(config, value):
if config.get('human', None):
@@ -109,6 +110,28 @@
return (collection, type)
+class EventCountingDatabase(AbstractSQLDatabase):
+ def __init__(self, fp):
+ super(EventCountingDatabase, self).__init__(fp.path)
+
+ def _db_version(self):
+ return schema_version
+
+ def _db_type(self):
+ return collection_types['Calendar']
+
+ def _countType(self, type):
+ return self._db_value_for_sql(
+ "SELECT COUNT(UID) FROM RESOURCE WHERE TYPE = (?)",
+ type)
+
+ def countEvents(self):
+ return self._countType('VEVENT')
+
+ def countTodos(self):
+ return self._countType('VTODO')
+
+
def getCalendarDataCounts(calendarCollection):
calCount = 0
eventCount = 0
@@ -119,18 +142,11 @@
if getResourceType(child) == (True, 'calendar'):
calCount += 1
- elif child.isfile():
- try:
- component = ical.Component.fromStream(child.open())
- except ValueError:
- # not a calendar file
- continue
+ db = EventCountingDatabase(child.child(db_prefix+'sqlite'))
- if component.resourceType() == 'VEVENT':
- eventCount += 1
+ eventCount += db.countEvents()
- elif component.resourceType() == 'VTODO':
- todoCount += 1
+ todoCount += db.countTodos()
return {'calendarCount': calCount,
'eventCount': eventCount,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070821/1d34781c/attachment.html
More information about the calendarserver-changes
mailing list