[Erp5-report] r43644 seb - in /erp5/trunk/products/ERP5Type: ./ patches/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Feb 23 23:49:49 CET 2011


Author: seb
Date: Wed Feb 23 23:49:49 2011
New Revision: 43644

URL: http://svn.erp5.org?rev=43644&view=rev
Log:
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.

Modified:
    erp5/trunk/products/ERP5Type/Base.py
    erp5/trunk/products/ERP5Type/patches/PropertyManager.py

Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=43644&r1=43643&r2=43644&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Base.py [utf8] Wed Feb 23 23:49:49 2011
@@ -827,14 +827,15 @@ class Base( CopyContainer,
   def _aq_key(self):
     return (self.portal_type, self.__class__)
 
-  def _propertyMap(self):
+  def _propertyMap(self, local_properties=False):
     """ Method overload - properties are now defined on the ptype """
     klass = self.__class__
     property_list = []
     # Get all the accessor holders for this portal type
-    if hasattr(klass, 'getAccessorHolderPropertyList'):
-      property_list += \
-          self.__class__.getAccessorHolderPropertyList()
+    if not local_properties:
+      if hasattr(klass, 'getAccessorHolderPropertyList'):
+        property_list += \
+            self.__class__.getAccessorHolderPropertyList()
 
     property_list += getattr(self, '_local_properties', [])
     return tuple(property_list)
@@ -1273,8 +1274,10 @@ class Base( CopyContainer,
           result = [result]
         return result
     if d is not _MARKER:
-      return ERP5PropertyManager.getProperty(self, key, d=d, **kw)
-    return ERP5PropertyManager.getProperty(self, key, **kw)
+      return ERP5PropertyManager.getProperty(self, key, d=d,
+                local_properties=True, **kw)
+    return ERP5PropertyManager.getProperty(self, key,
+                local_properties=True, **kw)
 
   security.declareProtected( Permissions.AccessContentsInformation, 'getPropertyList' )
   def getPropertyList(self, key, d=None):
@@ -1349,8 +1352,9 @@ class Base( CopyContainer,
     # If we are here, this means we do not use a property that
     # comes from an ERP5 PropertySheet, we should use the
     # PropertyManager
-    if ERP5PropertyManager.hasProperty(self,key):
-      ERP5PropertyManager._updateProperty(self, key, value)
+    if ERP5PropertyManager.hasProperty(self,key, local_properties=True):
+      ERP5PropertyManager._updateProperty(self, key, value,
+                          local_properties=True)
     else:
       ERP5PropertyManager._setProperty(self, key, value, type=type)
     # This should not be there, because this ignore all checks made by

Modified: erp5/trunk/products/ERP5Type/patches/PropertyManager.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/PropertyManager.py?rev=43644&r1=43643&r2=43644&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/PropertyManager.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/patches/PropertyManager.py [utf8] Wed Feb 23 23:49:49 2011
@@ -34,7 +34,7 @@ PropertyManager_manage_propertiesForm=DT
                                                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
     # is a string, an attempt will be made to convert
     # the value to the type of the existing property.
@@ -43,22 +43,25 @@ def PropertyManager_updateProperty(self,
       if not self.hasProperty(id):
           raise BadRequest, 'The property %s does not exist' % escape(id)
     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):
             value=type_converters[proptype](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'"""
-    for p in self.propertyIds():
+    for p in self.propertyIds(local_properties=local_properties):
         if id==p:
             return 1
     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
         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':
         value = getattr(self, id)
         expression = Expression(value)
@@ -68,10 +71,14 @@ def PropertyManager_getProperty(self, id
       return getattr(self, id)
     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
       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:
             return md.get('type', 'string')
     return None
@@ -138,9 +145,10 @@ def PropertyManager_delProperty(self, id
     self._local_properties=tuple(filter(lambda i, n=id: i['id'] != n,
                                   getattr(self, '_local_properties', ())))
 
-def PropertyManager_propertyIds(self):
+def PropertyManager_propertyIds(self, local_properties=False):
     """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):
     """Return a list of actual property objects """
@@ -150,7 +158,7 @@ def PropertyManager_propertyItems(self):
     """Return a list of (id,property) tuples """
     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 """
     property_map = list(self._properties)
     property_dict = {}



More information about the Erp5-report mailing list