entities are now changed only if entity hash changed which will limit number of events emitted

This commit is contained in:
azivner
2018-08-12 20:04:48 +02:00
parent 13f524fb39
commit 9fb0599c45
8 changed files with 41 additions and 20 deletions

View File

@@ -18,13 +18,21 @@ class Entity {
this[this.constructor.primaryKeyName] = utils.newEntityId();
}
const origHash = this.hash;
this.hash = this.generateHash();
this.isChanged = origHash !== this.hash;
}
generateHash() {
let contentToHash = "";
for (const propertyName of this.constructor.hashedProperties) {
contentToHash += "|" + this[propertyName];
}
this["hash"] = utils.hash(contentToHash).substr(0, 10);
return utils.hash(contentToHash).substr(0, 10);
}
async save() {