Replaced most properties in creature variables with links

instead of storing the entire property twice
This commit is contained in:
ThaumRystra
2023-11-09 23:05:05 +02:00
parent 84edd74ff3
commit 7eada9effe
8 changed files with 117 additions and 29 deletions

View File

@@ -19,6 +19,12 @@ export default function writeScope(creatureId, computation) {
// Mongo can't handle keys that start with a dollar sign
if (key[0] === '$' || key[0] === '_') continue;
// Remove empty objects
if (Object.keys(scope[key]).length === 0) {
delete scope[key];
continue;
}
// Remove large properties that aren't likely to be accessed
delete scope[key].parent;
delete scope[key].ancestors;
@@ -30,6 +36,11 @@ export default function writeScope(creatureId, computation) {
}
}
// If this is a creature property, replace the property with a link
if (scope[key]._id && scope[key].type) {
scope[key] = { _propId: scope[key]._id };
}
// Only update changed fields
if (!EJSON.equals(variables[key], scope[key])) {
if (!$set) $set = {};