Commit bb1a3bf2 authored by Aurel's avatar Aurel

define cache factory

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13084 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7b418fdb
......@@ -86,7 +86,8 @@ def getFieldDescription():\n
return property.get(\'description\', \'\')\n
return desc\n
\n
getFieldDescription = CachingMethod(getFieldDescription, (\'getFieldDescription\', form_id, field_id), cache_duration=None)\n
getFieldDescription = CachingMethod(getFieldDescription, (\'getFieldDescription\', form_id, field_id), \\\n
cache_factory=\'erp5_user_interface_long\')\n
\n
return getFieldDescription()\n
</string> </value>
......@@ -144,7 +145,6 @@ return getFieldDescription()\n
<string>_getattr_</string>
<string>field_id</string>
<string>getFieldDescription</string>
<string>None</string>
</tuple>
</value>
</item>
......
......@@ -74,7 +74,7 @@ navigation_box_render = CachingMethod(navigation_box_render,\n
("ERP5Site_renderCachedNavigationBox",\n
context.portal_membership.getAuthenticatedMember().getUserName(),\n
context.Localizer.get_selected_language()\n
),cache_duration=300)\n
),cache_factory=\'erp5_user_interface_short\')\n
return navigation_box_render()\n
</string> </value>
</item>
......
......@@ -122,7 +122,7 @@ def getFormGroupTitleAndId():\n
\n
getFormGroupTitleAndId = CachingMethod(getFormGroupTitleAndId,\n
("ERP5Site_getFormGroupTitleAndId", form.id, form.get_groups(include_empty=0)),\n
cache_duration=None)\n
cache_factory=\'erp5_user_interface_long\')\n
return getFormGroupTitleAndId()\n
</string> </value>
</item>
......@@ -178,7 +178,6 @@ return getFormGroupTitleAndId()\n
<string>form</string>
<string>getFormGroupTitleAndId</string>
<string>_getattr_</string>
<string>None</string>
</tuple>
</value>
</item>
......
340
\ No newline at end of file
345
\ No newline at end of file
......@@ -140,10 +140,11 @@ class PreferenceMethod(Method) :
if found :
return value
_getPreference = CachingMethod( _getPreference,
id='PreferenceTool.CachingMethod.%s' % self._preference_name)
id='PreferenceTool.CachingMethod.%s' % self._preference_name,
cache_factory='erp5_user_interface_short')
user_name = getSecurityManager().getUser().getId()
return _getPreference(user_name=user_name)
class PreferenceTool(BaseTool):
"""
PreferenceTool manages User Preferences / User profiles.
......@@ -206,10 +207,10 @@ class PreferenceTool(BaseTool):
prefs.append(pref)
prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority()))
return prefs
security.declareProtected(Permissions.View, 'getActivePreference')
def getActivePreference(self) :
""" returns the current preference for the user.
""" returns the current preference for the user.
Note that this preference may be read only. """
enabled_prefs = self._getSortedPreferenceList()
if len(enabled_prefs) > 0 :
......@@ -222,7 +223,7 @@ class PreferenceTool(BaseTool):
"""
if folder is None:
# as the preference tool is also a Folder, this method is called by
# page templates to get the list of document templates for self.
# page templates to get the list of document templates for self.
folder = self
# We must set the user_id as a parameter to make sure each
......@@ -236,7 +237,7 @@ class PreferenceTool(BaseTool):
return acceptable_templates
_getDocumentTemplateList = CachingMethod(_getDocumentTemplateList,
'portal_preferences.getDocumentTemplateList',
cache_duration=3000)
cache_factory='erp5_user_interface_medium')
allowed_content_types = map(lambda pti: pti.id,
folder.allowedContentTypes())
......
......@@ -170,7 +170,7 @@ class OOoDocument(File, ConversionCacheMixin):
def _getServerCoordinate(self):
"""
Returns OOo conversion server data from
Returns OOo conversion server data from
preferences
"""
pref = getToolByName(self, 'portal_preferences')
......@@ -233,7 +233,8 @@ class OOoDocument(File, ConversionCacheMixin):
return [[y,x] for x,y in allowed] # have to reverse tuple order
cached_getTargetFormatItemList = CachingMethod(cached_getTargetFormatItemList,
id = "OOoDocument_getTargetFormatItemList" )
id = "OOoDocument_getTargetFormatItemList",
cache_factory='erp5_core_short')
return cached_getTargetFormatItemList(self.getContentType())
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetFormatList')
......@@ -292,7 +293,7 @@ class OOoDocument(File, ConversionCacheMixin):
sp = self._mkProxy()
kw = sp.run_convert(self.getSourceReference(), enc(self._unpackData(self.data)))
self.oo_data = Pdata(dec(kw['data']))
# now we get text content
# now we get text content
text_data = self.extractTextContent()
self.setTextContent(text_data)
self._setMetaData(kw['meta'])
......@@ -531,5 +532,5 @@ class OOoDocument(File, ConversionCacheMixin):
manage_FTPstat = File.manage_FTPstat
# vim: syntax=python shiftwidth=2
# vim: syntax=python shiftwidth=2
......@@ -179,7 +179,8 @@ class ERP5GroupManager(BasePlugin):
if not NO_CACHE_MODE:
_getGroupsForPrincipal = CachingMethod(_getGroupsForPrincipal,
id='ERP5GroupManager_getGroupsForPrincipal')
id='ERP5GroupManager_getGroupsForPrincipal',
cache_factory='erp5_core_short')
return _getGroupsForPrincipal(
user_name=principal.getId(),
......
......@@ -108,7 +108,8 @@ class ERP5UserManager(BasePlugin):
return None
_authenticateCredentials = CachingMethod(_authenticateCredentials,
id='ERP5UserManager_authenticateCredentials')
id='ERP5UserManager_authenticateCredentials',
cache_factory='erp5_core_short')
return _authenticateCredentials(
login=credentials.get('login'),
password=credentials.get('password'),
......@@ -152,7 +153,8 @@ class ERP5UserManager(BasePlugin):
return tuple(user_info)
_enumerateUsers = CachingMethod(_enumerateUsers,
id='ERP5UserManager_enumerateUsers')
id='ERP5UserManager_enumerateUsers',
cache_factory='erp5_core_short')
if id is None:
id = login
......
......@@ -104,7 +104,7 @@ def _evaluateTales(instance=None, value=None):
econtext = createExpressionContext(instance)
return expression(econtext)
evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_duration=300)
evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_factory='erp5_core_short')
class Getter(Method):
"""
......
......@@ -467,7 +467,7 @@ class Base( CopyContainer,
return getattr(Base.aq_portal_type[ptype], id, None).__of__(self)
return None
def manage_historyCompare(self, rev1, rev2, REQUEST,
historyComparisonResults=''):
return Base.inheritedAttribute('manage_historyCompare')(
......@@ -560,7 +560,7 @@ class Base( CopyContainer,
'unable to create methods for PreferenceTool', e)
raise
Base.aq_preference_generated = 1
# Always try to return something after generation
if generated:
# We suppose that if we reach this point
......@@ -607,11 +607,11 @@ class Base( CopyContainer,
"""
from ZODB.utils import oid_repr
return oid_repr(self._p_oid)
def getSerial(self):
"""Return ODB Serial."""
return self._p_serial
def getHistorySerial(self):
"""Return ODB Serial, in the same format used for history keys"""
return '.'.join([str(x) for x in unpack('>HHHH', self._p_serial)])
......@@ -967,6 +967,7 @@ class Base( CopyContainer,
self._aq_dynamic('id') # Make sure _aq_dynamic has been called once
if hasattr(Base.aq_portal_type[self.portal_type], accessor_name):
method = getattr(self, accessor_name)
LOG("Base.py", 0, "method = %s, name = %s" %(method, accessor_name))
method(value, **kw)
return
if hasattr(Base.aq_portal_type[self.portal_type], public_accessor_name):
......@@ -983,7 +984,7 @@ class Base( CopyContainer,
else:
ERP5PropertyManager._setProperty(self, key, value, type=type)
# This should not be there, because this ignore all checks made by
# the PropertyManager. If there is problems, please complain to
# the PropertyManager. If there is problems, please complain to
# seb@nexedi.com
#except:
# # This should be removed if we want strict property checking
......@@ -1025,7 +1026,7 @@ class Base( CopyContainer,
#except ConflictError:
# raise
# This should not be there, because this ignore all checks made by
# the PropertyManager. If there is problems, please complain to
# the PropertyManager. If there is problems, please complain to
# seb@nexedi.com
#except:
# # This should be removed if we want strict property checking
......@@ -1487,7 +1488,7 @@ class Base( CopyContainer,
# We have been provided a string
path = target
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
else:
else:
# We have been provided an object
# Find the object
path = target.getRelativeUrl()
......@@ -1499,7 +1500,7 @@ class Base( CopyContainer,
def setDefaultValue(self, id, target, spec=(), filter=None, portal_type=()):
self._setDefaultValue(id, target, spec=spec, filter=filter, portal_type=portal_type)
self.reindexObject()
security.declareProtected( Permissions.View, '_getDefaultValue' )
def _getDefaultValue(self, id, spec=(), filter=None, portal_type=()):
path = self._getDefaultCategoryMembership(id, spec=spec, filter=filter,
......@@ -1607,7 +1608,7 @@ class Base( CopyContainer,
'getDefaultRelatedProperty' )
getDefaultRelatedProperty = _getDefaultRelatedProperty
security.declareProtected( Permissions.AccessContentsInformation,
'_getRelatedPropertyList' )
def _getRelatedPropertyList(self, id, property_name, spec=(), filter=None,
......@@ -1643,15 +1644,15 @@ class Base( CopyContainer,
references.append(self.portal_catalog.getObject(uid))
self._setValue(id, references, spec=spec, filter=filter, portal_type=portal_type, keep_default=keep_default)
security.declareProtected( Permissions.ModifyPortalContent, '_setValueUidList' )
security.declareProtected( Permissions.ModifyPortalContent, '_setValueUidList' )
_setValueUids = _setValueUidList # DEPRECATED
security.declareProtected( Permissions.ModifyPortalContent, 'setValueUidList' )
def setValueUidList(self, id, uids, spec=(), filter=None, portal_type=(), keep_default=1):
self._setValueUids(id, uids, spec=spec, filter=filter, portal_type=portal_type, keep_default=keep_default)
self.reindexObject()
security.declareProtected( Permissions.ModifyPortalContent, 'setValueUidList' )
security.declareProtected( Permissions.ModifyPortalContent, 'setValueUidList' )
setValueUids = setValueUidList # DEPRECATED
security.declareProtected( Permissions.ModifyPortalContent, '_setDefaultValueUid' )
......@@ -1858,7 +1859,7 @@ class Base( CopyContainer,
security.declareProtected( Permissions.View, 'Title' )
Title = getTitleOrId
security.declareProtected(Permissions.AccessContentsInformation,
'getTitleAndId')
def getTitleAndId(self):
......@@ -2314,7 +2315,8 @@ class Base( CopyContainer,
return getattr(ti, 'acquire_local_roles', True)
cached_getAcquireLocalRoles = CachingMethod(cached_getAcquireLocalRoles,
id='Base__getAcquireLocalRoles')
id='Base__getAcquireLocalRoles',
cache_factory='erp5_core_short')
return cached_getAcquireLocalRoles(portal_type=self.getPortalType())
security.declareProtected(Permissions.View, 'get_local_permissions')
......@@ -2577,7 +2579,7 @@ class Base( CopyContainer,
"""
Provides a quick access to precision without accessing the resource
value in ZODB. Here resource is the relative_url of the resource, such as
the result of self.getResource().
the result of self.getResource().
"""
def cached_getQuantityPrecisionFromResource(resource):
if resource:
......@@ -2588,7 +2590,8 @@ class Base( CopyContainer,
cached_getQuantityPrecisionFromResource = CachingMethod(
cached_getQuantityPrecisionFromResource,
id='Base_getQuantityPrecisionFromResource')
id='Base_getQuantityPrecisionFromResource',
cache_factory='erp5_core_short')
return cached_getQuantityPrecisionFromResource(resource)
......
......@@ -33,7 +33,7 @@ from CachePlugins.BaseCache import CachedMethodError
from zLOG import LOG, WARNING
DEFAULT_CACHE_SCOPE = 'GLOBAL'
DEFAULT_CACHE_FACTORY = 'erp5_user_interface'
DEFAULT_CACHE_FACTORY = 'erp5_user_interface_short'
is_cache_initialized = 0
def initializePortalCachingProperties(self):
......
......@@ -37,7 +37,7 @@ class PortalTypeClass(Constraint):
This is usefull to check that all objects of a given portal type are
consistant and that dynamic methods for the portal type can be
attached on the class.
Configuration example:
{ 'id' : 'portal_type_class',
'description' : 'The __class__ must be the same as the portal'\
......@@ -91,7 +91,7 @@ class PortalTypeClass(Constraint):
_getClassForPortalTypeCache = CachingMethod(
_getClassForPortalTypeCache,
"PortalTypeClass._getClassForPortalTypeCache",
cache_duration = 60 * 10
cache_factory = 'erp5_core_medium'
)
return _getClassForPortalTypeCache(obj.getPortalType())
......@@ -87,7 +87,7 @@ class FolderMixIn(ExtensionClass.Base):
else:
new_id = str(id)
if portal_type is None:
# XXX This feature is very confusing
# XXX This feature is very confusing
# And made the code more difficult to update
portal_type = container.allowedContentTypes()[0].id
......@@ -99,7 +99,7 @@ class FolderMixIn(ExtensionClass.Base):
factory_name = 'newTemp%s' %(portal_type.replace(' ', ''))
m = getattr(Document, factory_name)
return m(container, new_id)
myType = pt.getTypeInfo(container)
if myType is not None:
if not myType.allowType( portal_type ):
......@@ -115,12 +115,12 @@ class FolderMixIn(ExtensionClass.Base):
# TODO :the **kw makes it impossible to create content not based on
# ERP5TypeInformation, because factory method often do not support
# keywords arguments.
new_instance = container[new_id]
if kw != {} : new_instance._edit(force_update=1, **kw)
if immediate_reindex: new_instance.immediateReindexObject()
return new_instance
security.declareProtected(
Permissions.DeletePortalContent, 'deleteContent')
def deleteContent(self, id):
......@@ -144,7 +144,7 @@ class FolderMixIn(ExtensionClass.Base):
len(self)+1 to make sure generation works on an empty Folder.
"""
return '%X' % (randint(1, 10000 * (len(self) + 1)), )
def _generateNextId(self):
"""
Get the last generated Id, increment it until no object with generated
......@@ -314,7 +314,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
manage_options = ( CMFBTreeFolder.manage_options +
Historical.manage_options +
CMFCatalogAware.manage_options
......@@ -339,7 +339,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
if self._getOb(id, None) is None :
return id
return self.generateNewId()
#security.declareProtected( Permissions.DeletePortalContent, 'manage_delObjects' )
#manage_delObjects = CopyContainer.manage_delObjects
......@@ -689,15 +689,15 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
_getVisibleAllowedContentTypeList = CachingMethod(
_getVisibleAllowedContentTypeList,
id=("_getAllowedContentTypeTitleList", user, portal_path, portal_type),
cache_duration=None)
cache_factory='erp5_core_long')
return _getVisibleAllowedContentTypeList()
security.declarePublic('allowedContentTypes')
def allowedContentTypes( self ):
""" List portal_types which can be added in this folder / object.
Cache results.
Only paths are cached, because we must not cache objects.
This makes the result, even if based on cache, O(n) so it becomes quite
This makes the result, even if based on cache, O(n) so it becomes quite
costly with many allowed content types.
Example:
on Person (12 allowed content types): 1000 calls take 3s.
......@@ -717,7 +717,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
if not getSecurityManager().checkPermission(
Permissions.AddPortalContent, self):
return []
def _allowedContentTypes( portal_type=None, user=None, portal_path=None ):
# Sort the list for convenience -yo
# XXX This is not the best solution, because this does not take
......@@ -727,7 +727,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
type_list = CMFBTreeFolder.allowedContentTypes(self)
type_list.sort(compareTypes)
return ['/'.join(x.getPhysicalPath()) for x in type_list]
_allowedContentTypes = CachingMethod( _allowedContentTypes,
id = 'allowedContentTypes',
cache_duration = None)
......@@ -874,7 +874,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
"""
return self.getPortalObject().portal_preferences\
.getDocumentTemplateList(self)
security.declareProtected(Permissions.ModifyPortalContent, 'makeTemplate')
def makeTemplate(self):
"""
......@@ -899,7 +899,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
for o in self.objectValues():
if getattr(aq_base(o), 'makeTemplateInstance', None) is not None:
o.makeTemplateInstance()
def _delObject(self, id, dp=1):
"""
_delObject is redefined here in order to make sure
......
......@@ -1016,7 +1016,7 @@ class Catalog( Folder,
keys = keys.keys()
keys.sort()
return keys
return CachingMethod(_getColumnIds, id='SQLCatalog.getColumnIds', cache_duration=None)()
return CachingMethod(_getColumnIds, id='SQLCatalog.getColumnIds', cache_factory='erp5_core_long')()
def getColumnMap(self):
"""
......@@ -1035,7 +1035,7 @@ class Catalog( Folder,
if not keys.has_key(key): keys[key] = []
keys[key].append(table) # Is this inconsistent ?
return keys
return CachingMethod(_getColumnMap, id='SQLCatalog.getColumnMap', cache_duration=None)()
return CachingMethod(_getColumnMap, id='SQLCatalog.getColumnMap', cache_factory='erp5_core_long')()
def getResultColumnIds(self):
"""
......@@ -1696,7 +1696,7 @@ class Catalog( Folder,
%(table_index, table))
return table_index
return CachingMethod(_getTableIndex, id='SQLCatalog.getTableIndex', \
cache_duration=None)(table=table)
cache_factory='erp5_core_long')(table=table)
def getIndex(self, table, column_list):
......@@ -1731,7 +1731,7 @@ class Catalog( Folder,
LOG("SQLCatalog.getIndex", ERROR, "best_index = %s for table %s and columns %s" \
%(best_index, table, column_list))
return best_index
return CachingMethod(_getIndex, id='SQLCatalog.getIndex', cache_duration=None)\
return CachingMethod(_getIndex, id='SQLCatalog.getIndex', cache_factory='erp5_core_long')\
(table=table, column_list=column_list)
def buildSQLQuery(self, query_table='catalog', REQUEST=None,
......
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