[quills-dev] [Collective-checkins] r32125 - Quills/trunk
quills-dev at lists.etria.com quills-dev at lists.etria.comSat Oct 21 21:29:27 UTC 2006
- Previous message: [quills-dev] [Collective-checkins] r32107 - Quills/bundles/trunk
- Next message: [quills-dev] [Collective-checkins] r32125 - Quills/trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: tomster Date: Sat Oct 21 21:29:25 2006 New Revision: 32125 Modified: Quills/trunk/Weblog.py Quills/trunk/WeblogArchive.py Quills/trunk/interfaces.py Quills/trunk/syndication.py Log: !WeblogFeed and !WeblogFeedSource now honour the setting of maximum number of entries by default. Systems with a large number of entries would deteriorate rapidly in performance otherwise. (see r32123 and 32124) Further performance improvements: * provided a catalog-based implementation of `getModifiedDate` * override `getSortedFeedEntries` (which is what the templates in basesyndication call) because it has a generic but very expensive implementation in fatsyndication: since Quills' implementation of `getFeedEntries` returns sorted entries anyway, we can use that. '''Together, r32123, r32124 and this changeset provide dramatic performance improvements, especially for instances with a large(-ish) number of posts.''' On http://tomster.org/blog for instance, each call to the blog's frontpage used to trigger the lookup of 503 'real' (i.e. not brains) entries, which would then be sorted three(!!) times. First via the catalog query, then again to get the sorted entries for display, and finally once more to determine the effective modification date. Now only the first 15 objects get called and the two additional sortings have been eliminated, too. Modified: Quills/trunk/Weblog.py ============================================================================== --- Quills/trunk/Weblog.py (original) +++ Quills/trunk/Weblog.py Sat Oct 21 21:29:25 2006 @@ -299,13 +299,13 @@ return archives security.declareProtected(perms.View, 'getLazyEntries') - def getLazyEntries(self): + def getLazyEntries(self, num_of_entries=0): """Return all entries for this weblog as (lazy) catalog brains. """ archive = getattr(self.aq_inner.aq_explicit, 'archive') results = {} - lazy_entries = archive.getLazyEntries() + lazy_entries = archive.getLazyEntries(num_of_entries) return lazy_entries security.declareProtected(perms.ViewDrafts, 'getAllEntries') Modified: Quills/trunk/WeblogArchive.py ============================================================================== --- Quills/trunk/WeblogArchive.py (original) +++ Quills/trunk/WeblogArchive.py Sat Oct 21 21:29:25 2006 @@ -123,8 +123,10 @@ contentFilter=contentFilter) return [brain.getObject() for brain in brains] - def getLazyEntries(self): - """Return a list of lazy_maps for all entries under this archive""" + def getLazyEntries(self, num_of_entries=0): + """ Return a list of lazy_maps for entries under this archive. + Cut off at num_of_entries (or return _all_, if num_of_entries is 0) + """ path = '/'.join(self.getPhysicalPath()) results = self.portal_catalog( meta_type=['WeblogEntry',], @@ -133,15 +135,18 @@ sort_order = 'reverse', review_state = 'published') + if num_of_entries > 0: + results = results[:num_of_entries] return results def getNumberOfEntries(self): """simple counter method for lazy entries""" return len(self.getLazyEntries()) - def getEntries(self): + # 2006-10-21 tomster: this seems to never be called... can it go away? + def getEntries(self, num_of_entries=0): """Return a list of objects for all entries under this archive""" - maps = self.getLazyEntries() + maps = self.getLazyEntries(num_of_entries) results = [] for entry in maps: results.append(r.getObject()) Modified: Quills/trunk/interfaces.py ============================================================================== --- Quills/trunk/interfaces.py (original) +++ Quills/trunk/interfaces.py Sat Oct 21 21:29:25 2006 @@ -15,8 +15,10 @@ weblog. """ - def getLazyEntries(): - """Return all entries that are in the published state. + def getLazyEntries(num_of_items=0): + """ Return entries that are in the published state. + If num_of_items is zero, return _all_ items, otherwise + only num_of_items first entries. """ Modified: Quills/trunk/syndication.py ============================================================================== --- Quills/trunk/syndication.py (original) +++ Quills/trunk/syndication.py Sat Oct 21 21:29:25 2006 @@ -1,6 +1,9 @@ # Zope 3 imports from zope.interface import implements +# Zope 2 imports +from DateTime.DateTime import DateTime + # CMF imports from Products.CMFCore.utils import getToolByName @@ -12,7 +15,30 @@ class WeblogFeed(BaseFeed): - pass + """Adapter from Quills Weblog instances to IFeed + """ + + def getModifiedDate(self): + """See IFeed. + """ + + # Quills has the luxury of being able to compute the effective modification date + # in a much more efficient manner, i.e. by querying the catalog: + path = '/'.join(self.context.getPhysicalPath()) + results = self.context.portal_catalog( + meta_type=['WeblogEntry',], + path={'query':path, 'level': 0}, + sort_on = 'modified', + sort_order = 'reverse', + review_state = 'published') + + # just like fatsyndication, we return 'now', if there + # aren't any entries: + try: + return results[0].getObject().modified() + except IndexError: + return DateTime() + class WeblogFeedSource(BaseFeedSource): @@ -21,12 +47,20 @@ implements(IFeedSource) - def getFeedEntries(self): + def getFeedEntries(self, max_only=True): """See IFeedSoure """ - brains = self.context.getLazyEntries() + if max_only: + num_of_entries = self.getMaxEntries() + else: + num_of_entries = 0 # signals to fetch _all_ items + brains = self.context.getLazyEntries(num_of_entries) return [IFeedEntry(brain.getObject()) for brain in brains] + # Quills always returns sorted entries, so we can override fatsyndications + # expensive (but generic) implementation: + getSortedFeedEntries = getFeedEntries + class TopicFeed(BaseFeed): pass ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Collective-checkins mailing list Collective-checkins at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/collective-checkins
- Previous message: [quills-dev] [Collective-checkins] r32107 - Quills/bundles/trunk
- Next message: [quills-dev] [Collective-checkins] r32125 - Quills/trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the quills-dev mailing list