"storage/myisam/mi_check.c" did not exist on "6d35642fa7cbf7484ae6af0fb2f61b1b43567ae4"
Commit b280cb80 authored by Julien Muchembled's avatar Julien Muchembled

SimulationMovement.expand: optimization & bugfixes

- Stop calling rule.test() again.
- For Applied Rule objects that don't specialise to an applicable rule:
  - do not expand built ones;
  - and delete others (e.g. if a new rule matches, replace it).
parent 3365eecf
...@@ -316,7 +316,6 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin): ...@@ -316,7 +316,6 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin):
if not cache_enabled: if not cache_enabled:
cache[TREE_DELIVERED_CACHE_ENABLED] = 1 cache[TREE_DELIVERED_CACHE_ENABLED] = 1
applied_rule_dict = {}
applicable_rule_dict = {} applicable_rule_dict = {}
for rule in self._getApplicableRuleList(): for rule in self._getApplicableRuleList():
reference = rule.getReference() reference = rule.getReference()
...@@ -325,31 +324,27 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin): ...@@ -325,31 +324,27 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin):
# applicable rule per reference. It indicates a configuration error. # applicable rule per reference. It indicates a configuration error.
applicable_rule_dict.setdefault(reference, rule) applicable_rule_dict.setdefault(reference, rule)
applicable_rule_list = applicable_rule_dict.values()
for applied_rule in list(self.objectValues()): for applied_rule in list(self.objectValues()):
rule = applied_rule.getSpecialiseValue() rule = applied_rule.getSpecialiseValue()
# check if applied rule is already expanded, or if its portal try:
# rule is still applicable to this Simulation Movement applicable_rule_list.remove(rule)
except ValueError:
# XXX-Leo: possible optimization, it is likely that 'rule' is in if applied_rule._isTreeDelivered():
# applicable_rule_dict.values() (or actually, in reference = rule.getReference()
# self._getApplicableRuleList()). We should check if this is the try:
# case, and then not call rule.test(self), since the predicate applicable_rule_list.remove(applicable_rule_dict.pop(reference))
# tool will already have done it once. except KeyError:
if (rule.test(self) or pass
applied_rule._isTreeDelivered()):
applied_rule_dict[rule.getReference()] = applied_rule
else: else:
self._delObject(applied_rule.getId()) self._delObject(applied_rule.getId())
else:
applied_rule.expand(**kw)
for reference, rule in applicable_rule_dict.iteritems(): for rule in applicable_rule_list:
if reference not in applied_rule_dict: rule.constructNewAppliedRule(self, **kw).expand(**kw)
applied_rule = rule.constructNewAppliedRule(self, **kw)
applied_rule_dict[reference] = applied_rule
self.setCausalityState('expanded') self.setCausalityState('expanded')
# expand
for applied_rule in applied_rule_dict.itervalues():
applied_rule.expand(**kw)
# disable and clear cache # disable and clear cache
if not cache_enabled: if not cache_enabled:
......
...@@ -600,11 +600,7 @@ return context.generatePredicate( ...@@ -600,11 +600,7 @@ return context.generatePredicate(
key=lambda x: x.getSpecialiseValue().getReference()) key=lambda x: x.getSpecialiseValue().getReference())
# check the 1st applied rule is an application of invoicing_rule_1 # check the 1st applied rule is an application of invoicing_rule_1
self.assertEquals(applied_rule_list[0].getSpecialise(), self.assertEquals(applied_rule_list[0].getSpecialise(),
invoicing_rule_1.getRelativeUrl()) invoicing_rule_n.getRelativeUrl())
# but also check it's the same applied rule as before instead of a new
# one with the same specialization
self.assertEqual(applied_rule_list[0],
invoicing_rule_1_applied_rule)
self.assertEquals(applied_rule_list[1].getSpecialise(), self.assertEquals(applied_rule_list[1].getSpecialise(),
invoicing_rule_2.getRelativeUrl()) invoicing_rule_2.getRelativeUrl())
...@@ -655,7 +651,7 @@ return context.generatePredicate( ...@@ -655,7 +651,7 @@ return context.generatePredicate(
self.assertEquals(applied_rule.getSpecialise(), self.assertEquals(applied_rule.getSpecialise(),
invoicing_rule_1.getRelativeUrl()) invoicing_rule_1.getRelativeUrl())
# invalidate the rule and test that it is still there # invalidate the rule and test that it is gone
invoicing_rule_1.invalidate() invoicing_rule_1.invalidate()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -670,10 +666,7 @@ return context.generatePredicate( ...@@ -670,10 +666,7 @@ return context.generatePredicate(
delivery_rule.getRelativeUrl()) delivery_rule.getRelativeUrl())
self.assertEquals(root_applied_rule.objectCount(), 1) self.assertEquals(root_applied_rule.objectCount(), 1)
movement = root_applied_rule.objectValues()[0] movement = root_applied_rule.objectValues()[0]
self.assertEquals(movement.objectCount(), 1) self.assertEquals(movement.objectCount(), 0)
applied_rule = movement.objectValues()[0]
self.assertEquals(applied_rule.getSpecialise(),
invoicing_rule_1.getRelativeUrl())
# change the test method to one that fails, and test that the rule is # change the test method to one that fails, and test that the rule is
# removed # removed
......
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