🐎 mécanisme recalcul : si la situation ne change pas, le cache n'est pas supprimé

pull/1060/head
Johan Girod 2020-06-03 13:47:20 +02:00
parent 55eb4f9da1
commit 9e81494e5e
3 changed files with 26 additions and 12 deletions

View File

@ -70,8 +70,8 @@
"scripts": {
"prepare": "node scripts/prepare.js",
"build": "yarn run build:prod && yarn run build:legacy",
"build:prod": "yarn run webpack --config webpack.prod.js --progress --loglevel notice",
"build:legacy": "yarn run webpack --config webpack.prod.legacyBrowser.js --progress --loglevel notice",
"build:prod": "yarn run webpack --config webpack.prod.js",
"build:legacy": "yarn run webpack --config webpack.prod.legacyBrowser.js",
"build:stats": "webpack --config webpack.prod.js --profile --json > stats.json",
"build:analyze-bundle": "ANALYZE_BUNDLE=1 yarn run build",
"build:dev": "FR_SITE='http://localhost:5000${path}' EN_SITE='http://localhost:5001${path}' yarn run build",

View File

@ -431,7 +431,7 @@ impôt . foyer fiscal . impôt sur le revenu . impôt brut:
- recalcul:
règle: impôt brut . sans plafonnement
avec:
nombre de parts . rattachées: 0
nombre de parts . rattachées: 0 part
- (- quotient familial . plafond avantage)
impôt . foyer fiscal . impôt sur le revenu . impôt brut . sans plafonnement:

View File

@ -239,11 +239,27 @@ export const mecanismRecalcul = dottedNameContext => (recurse, k, v) => {
if (cache._meta.inRecalcul) {
return defaultNode(false)
}
const recalculCache = { _meta: { ...cache._meta, inRecalcul: true } } // Create an empty cache
const amendedSituation = map(
value => evaluateNode(cache, situation, parsedRules, value),
const amendedSituation = Object.fromEntries(
node.explanation.amendedSituation
.map(([originRule, replacement]) => [
evaluateNode(cache, situation, parsedRules, originRule),
evaluateNode(cache, situation, parsedRules, replacement)
])
.filter(
([originRule, replacement]) =>
originRule.nodeValue !== replacement.nodeValue ||
serializeUnit(originRule.unit) !== serializeUnit(replacement.unit)
)
.map(([originRule, replacement]) => [
originRule.dottedName,
replacement
])
)
// Optimisation : no need for recalcul if situation is the same
const recalculCache = Object.keys(amendedSituation).length
? { _meta: { ...cache._meta, inRecalcul: true } } // Create an empty cache
: cache
const evaluatedNode = evaluateNode(
recalculCache,
@ -266,12 +282,10 @@ export const mecanismRecalcul = dottedNameContext => (recurse, k, v) => {
}
}
const amendedSituation = Object.fromEntries(
Object.keys(v.avec).map(dottedName => [
recurse(dottedName).dottedName,
recurse(v.avec[dottedName])
])
)
const amendedSituation = Object.keys(v.avec).map(dottedName => [
recurse(dottedName),
recurse(v.avec[dottedName])
])
const defaultRuleToEvaluate = dottedNameContext
const nodeToEvaluate = recurse(v.règle ?? defaultRuleToEvaluate)
return {