Skip to content

Commit

Permalink
Merge 0df5416 into 581caf9
Browse files Browse the repository at this point in the history
  • Loading branch information
instification committed Sep 5, 2019
2 parents 581caf9 + 0df5416 commit 9f5b02b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Changelog
- Added css_modifier to extend css class of a filter item
[agitator]

Bug fixes:

- Use plone.memoize to cache groupby criteria
[instification]


3.2.1 (2019-08-07)
------------------
Expand Down
26 changes: 19 additions & 7 deletions src/collective/collectionfilter/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collective.collectionfilter.interfaces import IGroupByCriteria
from collective.collectionfilter.interfaces import IGroupByModifier
from collective.collectionfilter.utils import safe_encode
from plone.memoize import ram
from zope.component import getAdapters
from zope.component import getUtility
from zope.interface import implementer
Expand Down Expand Up @@ -53,6 +54,22 @@
LIST_SCALING = ['No Scaling', 'Linear', 'Logarithmic']


# Function for determining the cache key used by GroupByCreteria.
# There should be a separate cache for each site and the cache should be
# invalidated by modification to portal_catalog (changes to the indexes rather
# than changes to cataloged items).
def _groupby_cache_key(method, self):
portal = plone.api.portal.get()
site_path = '/'.join(portal.getPhysicalPath())
cache_key = site_path
# TODO: clear cache if portal_catalog is modified
# cat = portal.portal_catalog
# cat_changed = cat.undoable_transactions()[:1]
# cat_changed = len(cat_changed) > 0 and cat_changed[0]['time'] or ''
# cache_key = site_path + str(cat_changed)
return cache_key


@implementer(IGroupByCriteria)
class GroupByCriteria():
"""Global utility for retrieving and manipulating groupby criterias.
Expand All @@ -63,18 +80,13 @@ class GroupByCriteria():
"""

_groupby = None
_groupby = {}
groupby_modify = {}

@property
@ram.cache(_groupby_cache_key)
def groupby(self):

if self._groupby is not None:
# The groupby criteria are used at each IBeforeTraverseEvent - so
# on each request. This has to be fast, so exit early.
return self._groupby
self._groupby = {}

cat = plone.api.portal.get_tool('portal_catalog')
# get catalog metadata schema, but filter out items which cannot be
# used for grouping
Expand Down

0 comments on commit 9f5b02b

Please sign in to comment.