From a927a29712d114344c95aaf7c839515485be9b4b Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Sat, 16 Dec 2017 12:35:20 +0100 Subject: [PATCH] =?UTF-8?q?:racehorse:=20Am=C3=A9liore=20la=20performance?= =?UTF-8?q?=20de=20collectMissing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/generateQuestions.js | 15 ++++----------- source/engine/traverse.js | 13 ++++++++++--- test/inversion.test.js | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/engine/generateQuestions.js b/source/engine/generateQuestions.js index 173b4cd84..1b456485d 100644 --- a/source/engine/generateQuestions.js +++ b/source/engine/generateQuestions.js @@ -27,17 +27,10 @@ import { collectNodeMissing } from './evaluation' missingVariables: {variable: [objectives]} */ -export let collectMissingVariables = targets => - R.pipe( - R.chain(v => - R.pipe(collectNodeMissing, R.flatten, R.map(mv => [v.dottedName, mv]))(v) - ), - //groupBy missing variable but remove mv from value, it's now in the key - R.groupBy(R.last), - R.map(R.map(R.head)) - // below is a hand implementation of above... function composition can be nice sometimes :') - // R.reduce( (memo, [mv, dependencyOf]) => ({...memo, [mv]: [...(memo[mv] || []), dependencyOf] }), {}) - )(targets) +export let collectMissingVariables = targets => { + let missing = R.chain(collectNodeMissing, targets) + return R.groupBy(R.identity, missing) +} export let getNextSteps = (situationGate, analysis) => { let impact = ([, objectives]) => R.length(objectives) diff --git a/source/engine/traverse.js b/source/engine/traverse.js index 770b6e875..bbc69e886 100644 --- a/source/engine/traverse.js +++ b/source/engine/traverse.js @@ -119,18 +119,25 @@ let fillVariableNode = (rules, rule, filter) => parseResult => { explanation = parsedRule, missingVariables = variableIsCalculable ? [] : [dottedName] - let collectMissing = node => - nodeValue != null // notamment si situationValue != null + let collectMissing = node => { + let missingName = cacheName+":missing", + cached = cache[missingName] + + if (cached) return cached + + let result = nodeValue != null // notamment si situationValue != null ? [] : variableIsCalculable ? collectNodeMissing(parsedRule) : node.missingVariables + cache[missingName] = result + return result + } if (cached) { return cached } else { - cache[cacheName] = { ...rewriteNode(node, nodeValue, explanation, collectMissing), missingVariables diff --git a/test/inversion.test.js b/test/inversion.test.js index 8cec08fb7..45792732b 100644 --- a/test/inversion.test.js +++ b/test/inversion.test.js @@ -208,5 +208,5 @@ it('should collect missing variables fast', function() { let start = Date.now() let missing = collectMissingVariables(analysis.targets) let elapsed = Date.now()-start - expect(elapsed).to.be.below(200) + expect(elapsed).to.be.below(300) });