Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix note move to different parent in note cache
azivnerc55bc471db8b
diff --git a/src/entities/branch.js b/src/entities/branch.jsindex c24698a8a5..b4d509eeea 100644--- a/src/entities/branch.js+++ b/src/entities/branch.js@@ -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 reorderingstatic 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() {return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);}diff --git a/src/services/note_cache.js b/src/services/note_cache.jsindex 970799b7d1..d7ecb194ea 100644--- a/src/services/note_cache.js+++ b/src/services/note_cache.js@@ -260,20 +260,19 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity})else if (entityName === 'branches') {const branch = entity;- if (childToParent[branch.noteId]) {- childToParent[branch.noteId] = childToParent[branch.noteId].filter(noteId => noteId !== branch.parentNoteId)- }+ // first we remove records for original placement (if they exist)+ 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.parentNoteId];- delete childParentToBranchId[branch.noteId + '-' + branch.parentNoteId];- }- else {+ delete prefixes[branch.noteId + '-' + branch.origParentNoteId];+ delete childParentToBranchId[branch.noteId + '-' + branch.origParentNoteId];++ if (!branch.isDeleted) {+ // ... and then we create new recordsif (branch.prefix) {prefixes[branch.noteId + '-' + branch.parentNoteId] = branch.prefix;}- childToParent[branch.noteId] = childToParent[branch.noteId] || [];childToParent[branch.noteId].push(branch.parentNoteId);childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId;}diff --git a/src/services/repository.js b/src/services/repository.jsindex 61ed885e43..2bd1ca4538 100644--- a/src/services/repository.js+++ b/src/services/repository.js@@ -68,9 +68,11 @@ async function updateEntity(entity) {const clone = Object.assign({}, entity);+ // transient properties not supposed to be persisteddelete clone.jsonContent;delete clone.isOwned;delete clone.isChanged;+ delete clone.origParentNoteId;delete clone.__attributeCache;for (const key in clone) {