Commit 75eaa480 authored by Julien Muchembled's avatar Julien Muchembled

composition: fix severe memory leak (and speed loss)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39031 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 428fdd70
...@@ -104,11 +104,18 @@ class asComposedDocument(object): ...@@ -104,11 +104,18 @@ class asComposedDocument(object):
Collecting predicates (from effective models) is done lazily. Predicates can Collecting predicates (from effective models) is done lazily. Predicates can
be accessed through contentValues/objectValues. be accessed through contentValues/objectValues.
""" """
# Cache created classes to make other caches (like Base.aq_portal_type)
# useful and avoid memory leaks.
__class_cache = {}
def __new__(cls, orig_self, portal_type_list=None): def __new__(cls, orig_self, portal_type_list=None):
self = orig_self.asContext(_portal_type_list=portal_type_list) self = orig_self.asContext(_portal_type_list=portal_type_list)
base_class = self.__class__ base_class = self.__class__
self.__class__ = type(base_class.__name__, (cls, base_class), {}) try:
self.__class__ = cls.__class_cache[base_class]
except KeyError:
cls.__class_cache[base_class] = self.__class__ = \
type(base_class.__name__, (cls, base_class), {})
self._effective_model_list = \ self._effective_model_list = \
orig_self._findEffectiveSpecialiseValueList(portal_type_list) orig_self._findEffectiveSpecialiseValueList(portal_type_list)
return self return self
......
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