🐎 Améliore la performance de collectMissing

pull/138/head
Laurent Bossavit 2017-12-16 12:35:20 +01:00 committed by mama
parent d454e94ef6
commit a927a29712
3 changed files with 15 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)
});