Évitons de reparser les règles inutilement

pull/138/head
mama 2017-11-22 16:34:23 +01:00
parent 64f46358cc
commit be64e94e5d
2 changed files with 7 additions and 4 deletions

View File

@ -501,7 +501,8 @@ export let treatRuleRoot = (rules, rule) => {
// Pas de propriété explanation et jsx ici car on est parti du (mauvais) principe que 'non applicable si' et 'formule' sont particuliers, alors qu'ils pourraient être rangé avec les autres mécanismes
...parsedRoot,
evaluate,
collectMissing
collectMissing,
parsed: true
}
}
@ -571,7 +572,8 @@ export let analyse = (rules, targetInput) => situationGate => {
*/
treatOne = rule => treatRuleRoot(rules, rule),
//On fait ainsi pour chaque règle de la base.
parsedRules = R.map(treatOne, rules),
parsedAlready = R.all(r => r['parsed'], rules),
parsedRules = parsedAlready ? rules : R.map(treatOne, rules),
// TODO: we should really make use of namespaces at this level, in particular
// setRule in Rule.js needs to get smarter and pass dottedName
parsedTargets = targetNames.map(t => findRuleByName(parsedRules, t)),

View File

@ -49,7 +49,8 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (state, action) =
situationWithDefaults = assume(intermediateSituation, rulesDefaults)
let situationGate = situationWithDefaults(state),
analysis = analyse(flatRules, targetNames)(situationGate)
parsedRules = R.path(['analysis', 'parsedRules'], state),
analysis = analyse(parsedRules || flatRules, targetNames)(situationGate)
let newState = {
...state,
@ -80,7 +81,7 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (state, action) =
// where the answers were previously given default reasonable assumptions
if (done && assumptionsMade) {
let newSituation = intermediateSituation(state),
reanalysis = analyse(flatRules, targetNames)(newSituation),
reanalysis = analyse(analysis.parsedRules, targetNames)(newSituation),
extraSteps = nextSteps(newSituation, flatRules, reanalysis)
tracker.push(['trackEvent', 'done', 'extra questions: '+extraSteps.length])