Optimised when certain recompute functions are called to prevent unccessary work

This commit is contained in:
Stefan Zermatten
2021-02-04 13:59:08 +02:00
parent 326d1bd165
commit 6d1e3f078c
6 changed files with 24 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ import CreatureProperties from '/imports/api/creature/creatureProperties/Creatur
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
const updateCreatureProperty = new ValidatedMethod({
name: 'creatureProperties.update',
@@ -32,7 +33,7 @@ const updateCreatureProperty = new ValidatedMethod({
});
let rootCreature = getRootCreatureAncestor(property);
assertEditPermission(rootCreature, this.userId);
let pathString = path.join('.');
let modifier;
// unset empty values
@@ -45,8 +46,13 @@ const updateCreatureProperty = new ValidatedMethod({
selector: {type: property.type},
});
// Updating a property might change dependencies, unless we are certain
// it did not, a full recompute is required
// Some updates might cause other properties to become inactive
if ([
'applied', 'equipped', 'prepared', 'alwaysPrepared', 'disabled'
].includes(path[0])){
recomputeInactiveProperties(rootCreature._id);
}
// Updating a property is likely to change dependencies, do a full recompute
recomputeCreatureByDoc(rootCreature);
},
});