Commit 9fe1d68d authored by Julien Muchembled's avatar Julien Muchembled

CMFActivity: validate using single SQL request per message

parent 7e387bcb
...@@ -254,15 +254,14 @@ class SQLBase(Queue): ...@@ -254,15 +254,14 @@ class SQLBase(Queue):
LOG('SQLBase', INFO, 'Got a lock error, retrying...') LOG('SQLBase', INFO, 'Got a lock error, retrying...')
# Validation private methods # Validation private methods
def getDependentMessageList(self, db, activate_kw, same_queue): def getValidationSQL(self, quote, activate_kw, same_queue):
q = db.string_literal
validate_list = [] validate_list = []
for k, v in activate_kw.iteritems(): for k, v in activate_kw.iteritems():
if v is not None: if v is not None:
try: try:
method = getattr(self, '_validate_' + k, None) method = getattr(self, '_validate_' + k, None)
if method: if method:
validate_list.append(' AND '.join(method(v, q))) validate_list.append(' AND '.join(method(v, quote)))
except Exception: except Exception:
LOG('CMFActivity', WARNING, 'invalid %s value: %r' % (k, v), LOG('CMFActivity', WARNING, 'invalid %s value: %r' % (k, v),
error=True) error=True)
...@@ -271,21 +270,12 @@ class SQLBase(Queue): ...@@ -271,21 +270,12 @@ class SQLBase(Queue):
same_queue = False same_queue = False
break break
if validate_list: if validate_list:
message_list = [] return ("SELECT '%s' as activity, uid, date, processing_node,"
for line in Results(db.query( " priority, group_method_id, message FROM %s"
"SELECT * FROM %s WHERE processing_node > -10 AND (%s) LIMIT %s" % ( " WHERE processing_node > -10 AND (%s) LIMIT %s" % (
self.sql_table, ' OR '.join(validate_list), type(self).__name__, self.sql_table,
READ_MESSAGE_LIMIT if same_queue else 1), 0)): ' OR '.join(validate_list),
m = Message.load(line.message, READ_MESSAGE_LIMIT if same_queue else 1))
line=line,
uid=line.uid,
date=line.date,
processing_node=line.processing_node)
if not hasattr(m, 'order_validation_text'): # BBB
m.order_validation_text = self.getOrderValidationText(m)
message_list.append(m)
return message_list
return ()
def _validate_after_method_id(self, *args): def _validate_after_method_id(self, *args):
return sqltest_dict['method_id'](*args), return sqltest_dict['method_id'](*args),
......
...@@ -57,6 +57,7 @@ from Products.ERP5Type.UnrestrictedMethod import PrivilegedUser ...@@ -57,6 +57,7 @@ from Products.ERP5Type.UnrestrictedMethod import PrivilegedUser
from zope.site.hooks import setSite from zope.site.hooks import setSite
import transaction import transaction
from App.config import getConfiguration from App.config import getConfiguration
from Shared.DC.ZRDB.Results import Results
import Products.Localizer.patches import Products.Localizer.patches
localizer_lock = Products.Localizer.patches._requests_lock localizer_lock = Products.Localizer.patches._requests_lock
...@@ -1552,10 +1553,27 @@ class ActivityTool (BaseTool): ...@@ -1552,10 +1553,27 @@ class ActivityTool (BaseTool):
def getDependentMessageList(self, message, validating_queue=None): def getDependentMessageList(self, message, validating_queue=None):
activity_kw = message.activity_kw activity_kw = message.activity_kw
db = self.getSQLConnection() db = self.getSQLConnection()
return [(activity, m) quote = db.string_literal
for activity in activity_dict.itervalues() queries = []
for m in activity.getDependentMessageList( for activity in activity_dict.itervalues():
db, activity_kw, activity is validating_queue)] q = activity.getValidationSQL(
quote, activity_kw, activity is validating_queue)
if q:
queries.append(q)
if queries:
message_list = []
for line in Results(db.query("(%s)" % ") UNION ALL (".join(queries))):
activity = activity_dict[line.activity]
m = Message.load(line.message,
line=line,
uid=line.uid,
date=line.date,
processing_node=line.processing_node)
if not hasattr(m, 'order_validation_text'): # BBB
m.order_validation_text = activity.getOrderValidationText(m)
message_list.append((activity, m))
return message_list
return ()
# Required for tests (time shift) # Required for tests (time shift)
def timeShift(self, delay): def timeShift(self, delay):
......
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