Commit 780c29c7 authored by Yoshinori Okuji's avatar Yoshinori Okuji

More optimization to reduce locking time.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4221 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 96f4508c
...@@ -1019,15 +1019,15 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1019,15 +1019,15 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
methods = self.sql_catalog_object_list methods = self.sql_catalog_object_list
econtext_cache = {} econtext_cache = {}
argument_cache = {} argument_cache = {}
expression_cache = {}
method_kw_dict = {}
for method_name in methods: for method_name in methods:
kw = {} kw = {}
#LOG('catalogObjectList', 0, 'method_name = %s, self.isMethodFiltered(method_name) = %r, self.filter_dict.has_key(method_name) = %r' % (method_name, self.isMethodFiltered(method_name), self.filter_dict.has_key(method_name)))
if self.isMethodFiltered(method_name) and self.filter_dict.has_key(method_name): if self.isMethodFiltered(method_name) and self.filter_dict.has_key(method_name):
catalogged_object_list = [] catalogged_object_list = []
type_list = self.filter_dict[method_name]['type'] type_list = self.filter_dict[method_name]['type']
expression = self.filter_dict[method_name]['expression_instance'] expression = self.filter_dict[method_name]['expression_instance']
#LOG('catalogObjectList', 0, 'method_name = %s, type_list = %r, expression = %r' % (method_name, type_list, expression))
for object in object_list: for object in object_list:
# We will check if there is an filter on this # We will check if there is an filter on this
# method, if so we may not call this zsqlMethod # method, if so we may not call this zsqlMethod
...@@ -1036,12 +1036,15 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1036,12 +1036,15 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
if type_list and portal_type not in type_list: if type_list and portal_type not in type_list:
continue continue
elif expression is not None: elif expression is not None:
expression_key = (object.uid, self.filter_dict[method_name]['expression'])
try: try:
econtext = econtext_cache[object.uid] result = expression_cache[expression_key]
except KeyError: except KeyError:
econtext_cache[object.uid] = self.getExpressionContext(object) try:
econtext = econtext_cache[object.uid] econtext = econtext_cache[object.uid]
result = expression(econtext) except KeyError:
econtext = econtext_cache[object.uid] = self.getExpressionContext(object)
result = expression_cache[expression_key] = expression(econtext)
if not result: if not result:
continue continue
catalogged_object_list.append(object) catalogged_object_list.append(object)
...@@ -1051,6 +1054,8 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1051,6 +1054,8 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
if len(catalogged_object_list) == 0: if len(catalogged_object_list) == 0:
continue continue
method_kw_dict[method_name] = kw
#LOG('catalogObjectList', 0, 'method_name = %s' % (method_name,)) #LOG('catalogObjectList', 0, 'method_name = %s' % (method_name,))
method = getattr(self, method_name) method = getattr(self, method_name)
if method.meta_type == "Z SQL Method": if method.meta_type == "Z SQL Method":
...@@ -1075,6 +1080,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1075,6 +1080,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
append(value) append(value)
kw[arg] = value_list kw[arg] = value_list
for method_name in methods:
if method_name not in method_kw_dict:
continue
kw = method_kw_dict[method_name]
method = getattr(self, method_name)
method = aq_base(method).__of__(site_root.portal_catalog) # Use method in method = aq_base(method).__of__(site_root.portal_catalog) # Use method in
# the context of portal_catalog # the context of portal_catalog
# Alter/Create row # Alter/Create row
...@@ -1091,7 +1101,8 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1091,7 +1101,8 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
except ConflictError: except ConflictError:
raise raise
except: except:
LOG("SQLCatalog Warning: could not catalog objects with method %s" % method_name,100, str(object_list)) LOG("SQLCatalog Warning: could not catalog objects with method %s" % method_name,100, str(object_list),
error=sys.exc_info())
raise raise
if psyco is not None: psyco.bind(catalogObjectList) if psyco is not None: psyco.bind(catalogObjectList)
......
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