Commit 2bacf683 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Enable a transaction cache in catalogObjectList if possible.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4630 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 85ad9a8f
...@@ -58,6 +58,14 @@ try: ...@@ -58,6 +58,14 @@ try:
except ImportError: except ImportError:
psyco = None psyco = None
try:
from Products.ERP5Type.Cache import enableTransactionCache, disableTransactionCache
except ImportError:
def doNothing(context):
pass
enableTransactionCache = doNothing
disableTransactionCache = doNothing
UID_BUFFER_SIZE = 300 UID_BUFFER_SIZE = 300
valid_method_meta_type_list = ('Z SQL Method', 'Script (Python)') valid_method_meta_type_list = ('Z SQL Method', 'Script (Python)')
...@@ -1021,90 +1029,96 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1021,90 +1029,96 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
argument_cache = {} argument_cache = {}
expression_cache = {} expression_cache = {}
method_kw_dict = {} try:
for method_name in methods: enableTransactionCache(self)
kw = {}
if self.isMethodFiltered(method_name) and self.filter_dict.has_key(method_name): method_kw_dict = {}
catalogged_object_list = [] for method_name in methods:
type_list = self.filter_dict[method_name]['type'] kw = {}
expression = self.filter_dict[method_name]['expression_instance'] if self.isMethodFiltered(method_name) and self.filter_dict.has_key(method_name):
for object in object_list: catalogged_object_list = []
# We will check if there is an filter on this type_list = self.filter_dict[method_name]['type']
# method, if so we may not call this zsqlMethod expression = self.filter_dict[method_name]['expression_instance']
# for this object for object in object_list:
portal_type = object.getPortalType() # We will check if there is an filter on this
if type_list and portal_type not in type_list: # method, if so we may not call this zsqlMethod
continue # for this object
elif expression is not None: portal_type = object.getPortalType()
expression_key = (object.uid, self.filter_dict[method_name]['expression']) if type_list and portal_type not in type_list:
try: continue
result = expression_cache[expression_key] elif expression is not None:
except KeyError: 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 = econtext_cache[object.uid] = self.getExpressionContext(object) try:
result = expression_cache[expression_key] = expression(econtext) econtext = econtext_cache[object.uid]
if not result: except KeyError:
continue econtext = econtext_cache[object.uid] = self.getExpressionContext(object)
catalogged_object_list.append(object) result = expression_cache[expression_key] = expression(econtext)
else: if not result:
catalogged_object_list = object_list continue
catalogged_object_list.append(object)
if len(catalogged_object_list) == 0: else:
continue catalogged_object_list = object_list
method_kw_dict[method_name] = kw if len(catalogged_object_list) == 0:
continue
#LOG('catalogObjectList', 0, 'method_name = %s' % (method_name,))
method = getattr(self, method_name) method_kw_dict[method_name] = kw
if method.meta_type == "Z SQL Method":
# Build the dictionnary of values #LOG('catalogObjectList', 0, 'method_name = %s' % (method_name,))
arguments = method.arguments_src method = getattr(self, method_name)
for arg in split(arguments): if method.meta_type == "Z SQL Method":
value_list = [] # Build the dictionnary of values
append = value_list.append arguments = method.arguments_src
for object in catalogged_object_list: for arg in split(arguments):
try: value_list = []
value = argument_cache[(object.uid, arg)] append = value_list.append
except KeyError: for object in catalogged_object_list:
try: try:
value = getattr(object, arg, None) value = argument_cache[(object.uid, arg)]
if callable(value): except KeyError:
value = value() try:
except ConflictError: value = getattr(object, arg, None)
raise if callable(value):
except: value = value()
value = None except ConflictError:
argument_cache[(object.uid, arg)] = value raise
append(value) except:
kw[arg] = value_list value = None
argument_cache[(object.uid, arg)] = value
for method_name in methods: append(value)
if method_name not in method_kw_dict: kw[arg] = value_list
continue
kw = method_kw_dict[method_name] for method_name in methods:
method = getattr(self, method_name) if method_name not in method_kw_dict:
method = aq_base(method).__of__(site_root.portal_catalog) # Use method in continue
# the context of portal_catalog kw = method_kw_dict[method_name]
# Alter/Create row method = getattr(self, method_name)
try: method = aq_base(method).__of__(site_root.portal_catalog) # Use method in
#start_time = DateTime() # the context of portal_catalog
#LOG('catalogObjectList', 0, 'kw = %r, method_name = %r' % (kw, method_name)) # Alter/Create row
method(**kw) try:
#end_time = DateTime() #start_time = DateTime()
#if method_name not in profile_dict: #LOG('catalogObjectList', 0, 'kw = %r, method_name = %r' % (kw, method_name))
# profile_dict[method_name] = end_time.timeTime() - start_time.timeTime() method(**kw)
#else: #end_time = DateTime()
# profile_dict[method_name] += end_time.timeTime() - start_time.timeTime() #if method_name not in profile_dict:
#LOG('catalogObjectList', 0, '%s: %f seconds' % (method_name, profile_dict[method_name])) # profile_dict[method_name] = end_time.timeTime() - start_time.timeTime()
except ConflictError: #else:
raise # profile_dict[method_name] += end_time.timeTime() - start_time.timeTime()
except: #LOG('catalogObjectList', 0, '%s: %f seconds' % (method_name, profile_dict[method_name]))
LOG("SQLCatalog Warning: could not catalog objects with method %s" % method_name,100, str(object_list), except ConflictError:
error=sys.exc_info()) raise
raise except:
LOG("SQLCatalog Warning: could not catalog objects with method %s" % method_name,100, str(object_list),
error=sys.exc_info())
raise
finally:
disableTransactionCache(self)
if psyco is not None: psyco.bind(catalogObjectList) if psyco is not None: psyco.bind(catalogObjectList)
def uncatalogObject(self, path): def uncatalogObject(self, path):
......
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