Skip to content

Build your personal knowledge base with Trilium Notes

deleting without reloading the whole tree (at least on frontend)

zadam0267468cd538
diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.js
index 767fb5e10d..1b36769ac5 100644
--- a/src/public/javascripts/services/branches.js
+++ b/src/public/javascripts/services/branches.js
@@ -93,6 +93,8 @@ async function deleteNodes(nodes) {
await server.remove('branches/' + node.data.branchId);
}
+
+
// following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
// called with stopOnParent=true
let next = nodes[nodes.length - 1].getNextSibling();
@@ -112,9 +114,19 @@ async function deleteNodes(nodes) {
treeService.setCurrentNotePathToHash(next);
}
- infoService.showMessage("Note(s) has been deleted.");
+ await treeService.loadTreeCache();
+
+ const parentNoteIds = Array.from(new Set(nodes.map(node => node.getParent().data.noteId)));
+
+ for (const node of nodes) {
+ node.remove();
+ }
- await treeService.reload();
+ for (const parentNoteId of parentNoteIds) {
+ treeService.reloadNote(parentNoteId);
+ }
+
+ infoService.showMessage("Note(s) has been deleted.");
}
async function moveNodeUpInHierarchy(node) {
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js
index e8e7518a33..52bbf95381 100644
--- a/src/public/javascripts/services/tree.js
+++ b/src/public/javascripts/services/tree.js
@@ -491,7 +491,7 @@ function getHashValueFromAddress() {
return document.location.hash ? document.location.hash.substr(1) : ""; // strip initial #
}
-async function loadTree() {
+async function loadTreeCache() {
const resp = await server.get('tree');
startNotePath = resp.startNotePath;
@@ -499,7 +499,13 @@ async function loadTree() {
startNotePath = getHashValueFromAddress();
}
- return await treeBuilder.prepareTree(resp.notes, resp.branches, resp.relations);
+ treeCache.load(resp.notes, resp.branches, resp.relations);
+}
+
+async function loadTree() {
+ await loadTreeCache();
+
+ return await treeBuilder.prepareTree();
}
async function collapseTree(node = null) {
@@ -783,5 +789,6 @@ export default {
getHashValueFromAddress,
getNodesByNoteId,
checkFolderStatus,
- reloadNote
+ reloadNote,
+ loadTreeCache
};
\ No newline at end of file
diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.js
index 349e14e1df..ac7aeed579 100644
--- a/src/public/javascripts/services/tree_builder.js
+++ b/src/public/javascripts/services/tree_builder.js
@@ -6,11 +6,7 @@ import treeCache from "./tree_cache.js";
import messagingService from "./messaging.js";
import hoistedNoteService from "./hoisted_note.js";
-async function prepareTree(noteRows, branchRows, relations) {
- utils.assertArguments(noteRows, branchRows, relations);
-
- treeCache.load(noteRows, branchRows, relations);
-
+async function prepareTree() {
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
let hoistedBranch;
diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.js
index 000de702b0..93aa239de5 100644
--- a/src/public/javascripts/services/tree_cache.js
+++ b/src/public/javascripts/services/tree_cache.js
@@ -158,21 +158,21 @@ class TreeCache {
return;
}
- const branchId = treeCache.childParentToBranch[childNoteId + '-' + oldParentNoteId];
+ const branchId = this.childParentToBranch[childNoteId + '-' + oldParentNoteId];
const branch = await this.getBranch(branchId);
branch.parentNoteId = newParentNoteId;
- treeCache.childParentToBranch[childNoteId + '-' + newParentNoteId] = branchId;
- delete treeCache.childParentToBranch[childNoteId + '-' + oldParentNoteId]; // this is correct because we know that oldParentId isn't same as newParentId
+ this.childParentToBranch[childNoteId + '-' + newParentNoteId] = branchId;
+ delete this.childParentToBranch[childNoteId + '-' + oldParentNoteId]; // this is correct because we know that oldParentId isn't same as newParentId
// remove old associations
- treeCache.parents[childNoteId] = treeCache.parents[childNoteId].filter(p => p !== oldParentNoteId);
- treeCache.children[oldParentNoteId] = treeCache.children[oldParentNoteId].filter(ch => ch !== childNoteId);
+ this.parents[childNoteId] = this.parents[childNoteId].filter(p => p !== oldParentNoteId);
+ this.children[oldParentNoteId] = this.children[oldParentNoteId].filter(ch => ch !== childNoteId);
// add new associations
- treeCache.parents[childNoteId].push(newParentNoteId);
+ this.parents[childNoteId].push(newParentNoteId);
- const children = treeCache.children[newParentNoteId] = treeCache.children[newParentNoteId] || []; // this might be first child
+ const children = this.children[newParentNoteId] = this.children[newParentNoteId] || []; // this might be first child
// we try to put the note into precise order which might be used again by lazy-loaded nodes
if (beforeNoteId && children.includes(beforeNoteId)) {
diff --git a/src/services/tree.js b/src/services/tree.js
index 03b059c683..97bd5002ac 100644
--- a/src/services/tree.js
+++ b/src/services/tree.js
@@ -1,8 +1,5 @@
"use strict";
-import treeCache from "../public/javascripts/services/tree_cache.js";
-import treeBuilder from "../public/javascripts/services/tree_builder.js";
-
const sql = require('./sql');
const repository = require('./repository');
const Branch = require('../entities/branch');