Commit bf012dd0 authored by Sebastien Robin's avatar Sebastien Robin

getProperty/setProperty were very slow with local

properties, because the code of PropertyManager
was looking at all generated properties. This is
totally useless usually for PropertyManager to
deals with generated properties, because we use it
to manage local properties.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43644 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f3b8ab56
...@@ -827,11 +827,12 @@ class Base( CopyContainer, ...@@ -827,11 +827,12 @@ class Base( CopyContainer,
def _aq_key(self): def _aq_key(self):
return (self.portal_type, self.__class__) return (self.portal_type, self.__class__)
def _propertyMap(self): def _propertyMap(self, local_properties=False):
""" Method overload - properties are now defined on the ptype """ """ Method overload - properties are now defined on the ptype """
klass = self.__class__ klass = self.__class__
property_list = [] property_list = []
# Get all the accessor holders for this portal type # Get all the accessor holders for this portal type
if not local_properties:
if hasattr(klass, 'getAccessorHolderPropertyList'): if hasattr(klass, 'getAccessorHolderPropertyList'):
property_list += \ property_list += \
self.__class__.getAccessorHolderPropertyList() self.__class__.getAccessorHolderPropertyList()
...@@ -1273,8 +1274,10 @@ class Base( CopyContainer, ...@@ -1273,8 +1274,10 @@ class Base( CopyContainer,
result = [result] result = [result]
return result return result
if d is not _MARKER: if d is not _MARKER:
return ERP5PropertyManager.getProperty(self, key, d=d, **kw) return ERP5PropertyManager.getProperty(self, key, d=d,
return ERP5PropertyManager.getProperty(self, key, **kw) local_properties=True, **kw)
return ERP5PropertyManager.getProperty(self, key,
local_properties=True, **kw)
security.declareProtected( Permissions.AccessContentsInformation, 'getPropertyList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getPropertyList' )
def getPropertyList(self, key, d=None): def getPropertyList(self, key, d=None):
...@@ -1349,8 +1352,9 @@ class Base( CopyContainer, ...@@ -1349,8 +1352,9 @@ class Base( CopyContainer,
# If we are here, this means we do not use a property that # If we are here, this means we do not use a property that
# comes from an ERP5 PropertySheet, we should use the # comes from an ERP5 PropertySheet, we should use the
# PropertyManager # PropertyManager
if ERP5PropertyManager.hasProperty(self,key): if ERP5PropertyManager.hasProperty(self,key, local_properties=True):
ERP5PropertyManager._updateProperty(self, key, value) ERP5PropertyManager._updateProperty(self, key, value,
local_properties=True)
else: else:
ERP5PropertyManager._setProperty(self, key, value, type=type) ERP5PropertyManager._setProperty(self, key, value, type=type)
# This should not be there, because this ignore all checks made by # This should not be there, because this ignore all checks made by
......
...@@ -34,7 +34,7 @@ PropertyManager_manage_propertiesForm=DTMLFile('properties', ...@@ -34,7 +34,7 @@ PropertyManager_manage_propertiesForm=DTMLFile('properties',
property_extensible_schema__=1) property_extensible_schema__=1)
def PropertyManager_updateProperty(self, id, value): def PropertyManager_updateProperty(self, id, value, local_properties=False):
# Update the value of an existing property. If value # Update the value of an existing property. If value
# is a string, an attempt will be made to convert # is a string, an attempt will be made to convert
# the value to the type of the existing property. # the value to the type of the existing property.
...@@ -43,22 +43,25 @@ def PropertyManager_updateProperty(self, id, value): ...@@ -43,22 +43,25 @@ def PropertyManager_updateProperty(self, id, value):
if not self.hasProperty(id): if not self.hasProperty(id):
raise BadRequest, 'The property %s does not exist' % escape(id) raise BadRequest, 'The property %s does not exist' % escape(id)
if isinstance(value, str): if isinstance(value, str):
proptype=self.getPropertyType(id) or 'string' proptype=self.getPropertyType(id, local_properties=local_properties) \
or 'string'
if type_converters.has_key(proptype): if type_converters.has_key(proptype):
value=type_converters[proptype](value) value=type_converters[proptype](value)
self._setPropValue(id, value) self._setPropValue(id, value)
def PropertyManager_hasProperty(self, id): def PropertyManager_hasProperty(self, id, local_properties=False):
"""Return true if object has a property 'id'""" """Return true if object has a property 'id'"""
for p in self.propertyIds(): for p in self.propertyIds(local_properties=local_properties):
if id==p: if id==p:
return 1 return 1
return 0 return 0
def PropertyManager_getProperty(self, id, d=None, evaluate=1): def PropertyManager_getProperty(self, id, d=None, evaluate=1,
local_properties=False):
"""Get the property 'id', returning the optional second """Get the property 'id', returning the optional second
argument or None if no such property is found.""" argument or None if no such property is found."""
property_type = self.getPropertyType(id) property_type = self.getPropertyType(id,
local_properties=local_properties)
if evaluate and property_type == 'tales': if evaluate and property_type == 'tales':
value = getattr(self, id) value = getattr(self, id)
expression = Expression(value) expression = Expression(value)
...@@ -68,10 +71,14 @@ def PropertyManager_getProperty(self, id, d=None, evaluate=1): ...@@ -68,10 +71,14 @@ def PropertyManager_getProperty(self, id, d=None, evaluate=1):
return getattr(self, id) return getattr(self, id)
return d return d
def PropertyManager_getPropertyType(self, id): def PropertyManager_getPropertyType(self, id, local_properties=False):
"""Get the type of property 'id', returning None if no """Get the type of property 'id', returning None if no
such property exists""" such property exists"""
for md in self._propertyMap(): if local_properties:
property_map = getattr(self, '_local_properties', [])
else:
property_map = self._propertyMap()
for md in property_map:
if md['id']==id: if md['id']==id:
return md.get('type', 'string') return md.get('type', 'string')
return None return None
...@@ -138,9 +145,10 @@ def PropertyManager_delProperty(self, id): ...@@ -138,9 +145,10 @@ def PropertyManager_delProperty(self, id):
self._local_properties=tuple(filter(lambda i, n=id: i['id'] != n, self._local_properties=tuple(filter(lambda i, n=id: i['id'] != n,
getattr(self, '_local_properties', ()))) getattr(self, '_local_properties', ())))
def PropertyManager_propertyIds(self): def PropertyManager_propertyIds(self, local_properties=False):
"""Return a list of property ids """ """Return a list of property ids """
return map(lambda i: i['id'], self._propertyMap()) return map(lambda i: i['id'], self._propertyMap(
local_properties=local_properties))
def PropertyManager_propertyValues(self): def PropertyManager_propertyValues(self):
"""Return a list of actual property objects """ """Return a list of actual property objects """
...@@ -150,7 +158,7 @@ def PropertyManager_propertyItems(self): ...@@ -150,7 +158,7 @@ def PropertyManager_propertyItems(self):
"""Return a list of (id,property) tuples """ """Return a list of (id,property) tuples """
return map(lambda i,s=self: (i['id'],s.getProperty(i['id'])), self._propertyMap()) return map(lambda i,s=self: (i['id'],s.getProperty(i['id'])), self._propertyMap())
def PropertyManager_propertyMap(self): def PropertyManager_propertyMap(self, local_properties=False):
"""Return a tuple of mappings, giving meta-data for properties """ """Return a tuple of mappings, giving meta-data for properties """
property_map = list(self._properties) property_map = list(self._properties)
property_dict = {} property_dict = {}
......
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