Commit c629ee70 authored by Vincent Pelletier's avatar Vincent Pelletier

CMFActivity.Activity.SQLBase: Factorise validation processing_node threshold

Avoid repeating processing_node condition for every single activity
whose serialization_tag dependency is being checked. This reduces the
length and execution complexity of produced SQL.
parent 9fc690ed
...@@ -181,37 +181,42 @@ def _validate_after_tag_and_method_id(value, render_string): ...@@ -181,37 +181,42 @@ def _validate_after_tag_and_method_id(value, render_string):
# same order as the dependency value items expected by the next item # same order as the dependency value items expected by the next item
# - callable rendering given values into an SQL condition # - callable rendering given values into an SQL condition
# (value, render_string) -> str # (value, render_string) -> str
# - minimal applicable processing_node value (excluded)
_DEPENDENCY_TESTER_DICT = { _DEPENDENCY_TESTER_DICT = {
'after_method_id': ( 'after_method_id': (
('method_id', ), ('method_id', ),
sqltest_dict['method_id'], sqltest_dict['method_id'],
DEPENDENCY_IGNORED_ERROR_STATE,
), ),
'after_path': ( 'after_path': (
('path', ), ('path', ),
sqltest_dict['path'], sqltest_dict['path'],
DEPENDENCY_IGNORED_ERROR_STATE,
), ),
'after_message_uid': ( 'after_message_uid': (
('uid', ), ('uid', ),
sqltest_dict['uid'], sqltest_dict['uid'],
DEPENDENCY_IGNORED_ERROR_STATE,
), ),
'after_path_and_method_id': ( 'after_path_and_method_id': (
('path', 'method_id'), ('path', 'method_id'),
_validate_after_path_and_method_id, _validate_after_path_and_method_id,
DEPENDENCY_IGNORED_ERROR_STATE,
), ),
'after_tag': ( 'after_tag': (
('tag', ), ('tag', ),
sqltest_dict['tag'], sqltest_dict['tag'],
DEPENDENCY_IGNORED_ERROR_STATE,
), ),
'after_tag_and_method_id': ( 'after_tag_and_method_id': (
('tag', 'method_id'), ('tag', 'method_id'),
_validate_after_tag_and_method_id, _validate_after_tag_and_method_id,
DEPENDENCY_IGNORED_ERROR_STATE,
), ),
'serialization_tag': ( 'serialization_tag': (
('serialization_tag', ), ('serialization_tag', ),
lambda value, render_string: ( sqltest_dict['serialization_tag'],
'processing_node > -1 AND ' + -1,
sqltest_dict['serialization_tag'](value, render_string)
),
), ),
} }
...@@ -460,7 +465,7 @@ CREATE TABLE %s ( ...@@ -460,7 +465,7 @@ CREATE TABLE %s (
dependency_value, dependency_value,
) in message.activity_kw.iteritems(): ) in message.activity_kw.iteritems():
try: try:
column_list, _ = dependency_tester_dict[dependency_name] column_list, _, _ = dependency_tester_dict[dependency_name]
except KeyError: except KeyError:
continue continue
# There are 2 types of dependencies: # There are 2 types of dependencies:
...@@ -569,14 +574,16 @@ CREATE TABLE %s ( ...@@ -569,14 +574,16 @@ CREATE TABLE %s (
if not dependency_value_dict: if not dependency_value_dict:
# No more non-blocked message for this dependency, skip it. # No more non-blocked message for this dependency, skip it.
continue continue
column_list, to_sql = dependency_tester_dict[dependency_name] column_list, to_sql, min_processing_node = dependency_tester_dict[
dependency_name
]
row2key = ( row2key = (
_ITEMGETTER0 _ITEMGETTER0
if len(column_list) == 1 else if len(column_list) == 1 else
_IDENTITY _IDENTITY
) )
base_sql_suffix = ' WHERE processing_node > %i AND (%%s) LIMIT 1)' % ( base_sql_suffix = ' WHERE processing_node > %i AND (%%s) LIMIT 1)' % (
DEPENDENCY_IGNORED_ERROR_STATE, min_processing_node,
) )
sql_suffix_list = [ sql_suffix_list = [
base_sql_suffix % to_sql(dependency_value, quote) base_sql_suffix % to_sql(dependency_value, quote)
......
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