fix note move to different parent in note cache

This commit is contained in:
azivner 2018-08-31 19:55:56 +02:00
parent fdc3a7a7f2
commit c55bc471db
3 changed files with 17 additions and 9 deletions

View File

@ -27,6 +27,13 @@ class Branch extends Entity {
// notePosition is not part of hash because it would produce a lot of updates in case of reordering // notePosition is not part of hash because it would produce a lot of updates in case of reordering
static get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "isDeleted", "prefix"]; } static get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "isDeleted", "prefix"]; }
constructor(row = {}) {
super(row);
// used to detect move in note tree
this.origParentNoteId = this.parentNoteId;
}
async getNote() { async getNote() {
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
} }

View File

@ -260,20 +260,19 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity})
else if (entityName === 'branches') { else if (entityName === 'branches') {
const branch = entity; const branch = entity;
if (childToParent[branch.noteId]) { // first we remove records for original placement (if they exist)
childToParent[branch.noteId] = childToParent[branch.noteId].filter(noteId => noteId !== branch.parentNoteId) childToParent[branch.noteId] = childToParent[branch.noteId] || [];
} childToParent[branch.noteId] = childToParent[branch.noteId].filter(noteId => noteId !== branch.origParentNoteId);
if (branch.isDeleted) { delete prefixes[branch.noteId + '-' + branch.origParentNoteId];
delete prefixes[branch.noteId + '-' + branch.parentNoteId]; delete childParentToBranchId[branch.noteId + '-' + branch.origParentNoteId];
delete childParentToBranchId[branch.noteId + '-' + branch.parentNoteId];
} if (!branch.isDeleted) {
else { // ... and then we create new records
if (branch.prefix) { if (branch.prefix) {
prefixes[branch.noteId + '-' + branch.parentNoteId] = branch.prefix; prefixes[branch.noteId + '-' + branch.parentNoteId] = branch.prefix;
} }
childToParent[branch.noteId] = childToParent[branch.noteId] || [];
childToParent[branch.noteId].push(branch.parentNoteId); childToParent[branch.noteId].push(branch.parentNoteId);
childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId; childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId;
} }

View File

@ -68,9 +68,11 @@ async function updateEntity(entity) {
const clone = Object.assign({}, entity); const clone = Object.assign({}, entity);
// transient properties not supposed to be persisted
delete clone.jsonContent; delete clone.jsonContent;
delete clone.isOwned; delete clone.isOwned;
delete clone.isChanged; delete clone.isChanged;
delete clone.origParentNoteId;
delete clone.__attributeCache; delete clone.__attributeCache;
for (const key in clone) { for (const key in clone) {