Continued iterating on calculations, added failing test for bugs found

This commit is contained in:
Stefan Zermatten
2021-09-27 17:26:52 +02:00
parent 85e8756d1d
commit b0ee5cd304
9 changed files with 67 additions and 16 deletions

View File

@@ -1,12 +1,12 @@
import { Meteor } from 'meteor/meteor'
import { isEqual, forOwn } from 'lodash';
import { isEqual } from 'lodash';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import propertySchemasIndex from '/imports/api/properties/computedOnlyPropertySchemasIndex.js';
export default function writeAlteredProperties(computation){
let bulkWriteOperations = [];
// Loop through all properties on the memo
forOwn(computation.propsById, changed => {
computation.props.forEach(changed => {
let schema = propertySchemasIndex[changed.type];
if (!schema){
console.warn('No schema for ' + changed.type);
@@ -36,6 +36,9 @@ function addChangedKeysToOp(op, keys, original, changed) {
// and compile an operation that sets all those keys
for (let key of keys){
if (!isEqual(original[key], changed[key])){
console.log('not equal: ', key);
console.log(original[key])
console.log(changed[key])
if (!op) op = newOperation(original._id, changed.type);
let value = changed[key];
if (value === undefined){
@@ -83,6 +86,7 @@ function addUnsetOp(op, key){
// compensation without needing to roll back changes, which causes multiple
// expensive redraws of the character sheet
function writePropertiesSequentially(bulkWriteOps){
console.log({opsLength: bulkWriteOps.length});
bulkWriteOps.forEach(op => {
let updateOneOrMany = op.updateOne || op.updateMany;
CreatureProperties.update(updateOneOrMany.filter, updateOneOrMany.update, {
@@ -91,6 +95,7 @@ function writePropertiesSequentially(bulkWriteOps){
bypassCollection2: true,
});
});
console.log('finished writing ops');
}
// This is more efficient on the database, but significantly less efficient