Commit 41c88615 authored by Vincent Pelletier's avatar Vincent Pelletier

Implement getBaseCategoryDict, a cached version of getBaseCategoryList which...

Implement getBaseCategoryDict, a cached version of getBaseCategoryList which should be used to check if a base category is present (dict key searching is O(1), which is always better than list searching, even if sorted).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9709 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5d9c40c4
......@@ -41,6 +41,7 @@ from Products.CMFCore.PortalFolder import PortalFolder
from Products.ERP5Type.CopySupport import CopyContainer
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Document import newTempBase
from Products.ERP5Type.Cache import CachingMethod
from zLOG import LOG
......@@ -121,6 +122,16 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
security.declareProtected(Permissions.AccessContentsInformation, 'getUids')
getUids = getCategoryParentUidList
def getBaseCategoryDict(self):
"""
Cached method to which resturns a dict with category names as keys, and None as values.
This allows to search for an element existence in the list faster.
ie: if x in self.getPortalObject().portal_categories.getBaseCategoryDict()
"""
def getBaseCategoryDict(self):
return dict.fromkeys(self.getBaseCategoryList(), None)
return CachingMethod(getBaseCategoryDict, 'portal_categories.getBaseCategoryDict', cache_duration=None)(self)
def updateRelatedContent(self, context,
previous_category_url, new_category_url):
"""See CMFCategory.CategoryTool.updateRelatedContent
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment