Commit 18118d18 authored by Jérome Perrin's avatar Jérome Perrin

Added a cache on getPreference


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4370 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 51c2b475
......@@ -26,7 +26,7 @@
#
##############################################################################
from AccessControl import ClassSecurityInfo
from AccessControl import ClassSecurityInfo, getSecurityManager
from Globals import InitializeClass, DTMLFile
from Acquisition import aq_base
......@@ -83,10 +83,12 @@ class PreferenceTool(BaseTool):
security.declareProtected(Permissions.View, "getPreference")
def getPreference(self, pref_name) :
""" get the preference on the most appopriate Preference object. """
def _getPreference(self, pref_name="", user_name="") :
found = 0
MARKER = []
for pref in self._getMostAppropriatePreferences() :
attr = getattr(pref, pref_name, None)
if attr is not None :
attr = getattr(pref, pref_name, MARKER)
if attr is not MARKER :
found = 1
# test the attr is set
if callable(attr) :
......@@ -97,6 +99,10 @@ class PreferenceTool(BaseTool):
return attr
if found :
return attr
_getPreference = CachingMethod( _getPreference,
id='PreferenceTool.CachingMethod')
user_name = getSecurityManager().getUser().getId()
return _getPreference(self, pref_name=pref_name, user_name=user_name)
security.declareProtected(Permissions.ModifyPortalContent, "setPreference")
def setPreference(self, pref_name, value) :
......
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