🐎 Améliore la performance de collectMissing
parent
d454e94ef6
commit
a927a29712
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue