From db4b73b136069e5f7c1dcf946f04c6d0ab6a0b26 Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine <arnaud.fontaine@nexedi.com> Date: Thu, 8 Mar 2012 10:40:16 +0900 Subject: [PATCH] Cache the results of getVersionPriorityNameList as it's called very often when loading Components. --- product/ERP5/ERP5Site.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/product/ERP5/ERP5Site.py b/product/ERP5/ERP5Site.py index 25691e9ce6..5c32ba25aa 100644 --- a/product/ERP5/ERP5Site.py +++ b/product/ERP5/ERP5Site.py @@ -465,6 +465,12 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): self._version_priority_list = value + # Reset cached value of getVersionPriorityNameList() if present + try: + del self._v_version_priority_name_list + except AttributeError: + pass + if not getattr(self, '_v_bootstrapping', False): self.portal_components.resetOnceAtTransactionBoundary() @@ -474,9 +480,15 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): security.declareProtected(Permissions.AccessContentsInformation, 'getVersionPriorityNameList') def getVersionPriorityNameList(self): - # XXX-arnau: should be cached? - return [name.split('|')[0].strip() - for name in self.getVersionPriorityList()] + """ + Get only the version names ordered by priority and cache it as it is used + very often in Component import hooks + """ + if getattr(self, '_v_version_priority_name_list', None) is None: + self._v_version_priority_name_list = \ + [name.split('|')[0].strip() for name in self.getVersionPriorityList()] + + return self._v_version_priority_name_list security.declareProtected(Permissions.AccessContentsInformation, 'getUid') def getUid(self): -- 2.30.9