fix filing entity changes for deleted notes

This commit is contained in:
zadam 2023-02-10 09:16:32 +01:00
parent 346f6edd7e
commit c67644a2e3
2 changed files with 31 additions and 5 deletions

View file

@ -152,6 +152,10 @@ class Becca {
.replace('_', '')
);
if (!(camelCaseEntityName in this)) {
throw new Error(`Unknown entity name '${camelCaseEntityName}' (original argument '${entityName}')`);
}
return this[camelCaseEntityName][entityId];
}

View file

@ -100,16 +100,38 @@ function fillEntityChanges(entityName, entityPrimaryKey, condition = '') {
if (existingRows === 0) {
createdCount++;
const entity = becca.getEntity(entityName, entityId);
let hash;
let utcDateChanged;
let isSynced;
if (entityName.endsWith("_contents")) {
// FIXME: hacky, not sure if it might cause some problems
hash = "fake value";
utcDateChanged = dateUtils.utcNowDateTime();
isSynced = true; // contents are always synced
} else {
const entity = becca.getEntity(entityName, entityId);
if (entity) {
hash = entity?.generateHash() || "|deleted";
utcDateChanged = entity?.getUtcDateChanged() || dateUtils.utcNowDateTime();
isSynced = entityName !== 'options' || !!entity?.isSynced;
} else {
// entity might be null (not present in becca) when it's deleted
// FIXME: hacky, not sure if it might cause some problems
hash = "deleted";
utcDateChanged = dateUtils.utcNowDateTime();
isSynced = true; // deletable (the ones with isDeleted) entities are synced
}
}
// entity might be null (not present in becca) when it's deleted
addEntityChange({
entityName,
entityId,
hash: entity?.generateHash() || "|deleted",
hash: hash,
isErased: false,
utcDateChanged: entity?.getUtcDateChanged() || dateUtils.utcNowDateTime(),
isSynced: entityName !== 'options' || !!entity?.isSynced
utcDateChanged: utcDateChanged,
isSynced: isSynced
});
}
}