From 0c4492bcd033505c03dcb332d639d978262096e3 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 1 Jun 2023 23:14:17 +0200 Subject: [PATCH] invalidate attribute cache on branch create/update, fixes #3994 --- src/becca/becca_loader.js | 43 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index 82dd09e42..dd8e990a4 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -69,25 +69,6 @@ function reload() { require('../services/ws').reloadFrontend(); } -/** - * This gets run on entity being created or updated. - * - * @param entityName - * @param entityRow - can be a becca entity (change comes from this trilium instance) or just a row (from sync). - * Should be therefore treated as a row. - */ -function postProcessEntityUpdate(entityName, entityRow) { - if (entityName === 'notes') { - noteUpdated(entityRow); - } else if (entityName === 'branches') { - branchUpdated(entityRow); - } else if (entityName === 'attributes') { - attributeUpdated(entityRow); - } else if (entityName === 'note_reordering') { - noteReorderingUpdated(entityRow); - } -} - eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => { if (!becca.loaded) { return; @@ -119,6 +100,25 @@ eventService.subscribeBeccaLoader(eventService.ENTITY_CHANGED, ({entityName, en postProcessEntityUpdate(entityName, entity); }); +/** + * This gets run on entity being created or updated. + * + * @param entityName + * @param entityRow - can be a becca entity (change comes from this trilium instance) or just a row (from sync). + * Should be therefore treated as a row. + */ +function postProcessEntityUpdate(entityName, entityRow) { + if (entityName === 'notes') { + noteUpdated(entityRow); + } else if (entityName === 'branches') { + branchUpdated(entityRow); + } else if (entityName === 'attributes') { + attributeUpdated(entityRow); + } else if (entityName === 'note_reordering') { + noteReorderingUpdated(entityRow); + } +} + eventService.subscribeBeccaLoader([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entityId}) => { if (!becca.loaded) { return; @@ -156,6 +156,7 @@ function branchDeleted(branchId) { .filter(parentBranch => parentBranch.branchId !== branch.branchId); if (childNote.parents.length > 0) { + // subtree notes might lose some inherited attributes childNote.invalidateSubTree(); } } @@ -185,6 +186,10 @@ function branchUpdated(branchRow) { if (childNote) { childNote.flatTextCache = null; childNote.sortParents(); + + // notes in the subtree can get new inherited attributes + // this is in theory needed upon branch creation, but there's no create event for sync changes + childNote.invalidateSubTree(); } const parentNote = becca.notes[branchRow.parentNoteId];