Denormalised slot fill total to database
This commit is contained in:
@@ -9,6 +9,7 @@ import writeAlteredProperties from '/imports/api/creature/computation/writeAlter
|
|||||||
import writeCreatureVariables from '/imports/api/creature/computation/writeCreatureVariables.js';
|
import writeCreatureVariables from '/imports/api/creature/computation/writeCreatureVariables.js';
|
||||||
import { recomputeDamageMultipliersById } from '/imports/api/creature/denormalise/recomputeDamageMultipliers.js';
|
import { recomputeDamageMultipliersById } from '/imports/api/creature/denormalise/recomputeDamageMultipliers.js';
|
||||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
|
import recomputeSlotFullness from '/imports/api/creature/denormalise/recomputeSlotFullness.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/Creatures.js';
|
||||||
|
|
||||||
export const recomputeCreature = new ValidatedMethod({
|
export const recomputeCreature = new ValidatedMethod({
|
||||||
@@ -117,5 +118,6 @@ export function recomputeCreatureByDoc(creature){
|
|||||||
writeAlteredProperties(computationMemo);
|
writeAlteredProperties(computationMemo);
|
||||||
writeCreatureVariables(computationMemo, creatureId);
|
writeCreatureVariables(computationMemo, creatureId);
|
||||||
recomputeDamageMultipliersById(creatureId);
|
recomputeDamageMultipliersById(creatureId);
|
||||||
|
recomputeSlotFullness(creatureId);
|
||||||
return computationMemo;
|
return computationMemo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||||
|
// n + 1 database queries + n potential updates for n slots. Could be sped up.
|
||||||
|
export default function recomputeSlotFullness(ancestorId){
|
||||||
|
CreatureProperties.find({
|
||||||
|
'ancestors.id': ancestorId,
|
||||||
|
type: 'propertySlot',
|
||||||
|
}).forEach(slot => {
|
||||||
|
let children = CreatureProperties.find({
|
||||||
|
'parent.id': slot._id,
|
||||||
|
removed: {$ne: true},
|
||||||
|
}).fetch();
|
||||||
|
let totalFilled = 0;
|
||||||
|
children.forEach(child => {
|
||||||
|
if (child.type === 'slotFiller'){
|
||||||
|
totalFilled += child.slotQuantityFilled;
|
||||||
|
} else {
|
||||||
|
totalFilled++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (slot.totalFilled !== totalFilled){
|
||||||
|
CreatureProperties.update(slot._id, {
|
||||||
|
$set: {totalFilled},
|
||||||
|
}, {
|
||||||
|
selector: {type: 'propertySlot'}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -50,6 +50,10 @@ const ComputedOnlySlotSchema = new SimpleSchema({
|
|||||||
'slotConditionErrors.$':{
|
'slotConditionErrors.$':{
|
||||||
type: ErrorSchema,
|
type: ErrorSchema,
|
||||||
},
|
},
|
||||||
|
totalFilled: {
|
||||||
|
type: SimpleSchema.Integer,
|
||||||
|
defaultValue: 0,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const ComputedSlotSchema = new SimpleSchema()
|
const ComputedSlotSchema = new SimpleSchema()
|
||||||
|
|||||||
@@ -135,14 +135,6 @@ export default {
|
|||||||
'parent.id': slot._id,
|
'parent.id': slot._id,
|
||||||
removed: {$ne: true},
|
removed: {$ne: true},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
slot.totalFilled = 0;
|
|
||||||
slot.children.forEach(child => {
|
|
||||||
if (child.type === 'slotFiller'){
|
|
||||||
slot.totalFilled += child.slotQuantityFilled;
|
|
||||||
} else {
|
|
||||||
slot.totalFilled++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return slot;
|
return slot;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user