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
make note tree initial load non-lazy
zadam90d091aedb52
diff --git a/libraries/fancytree/jquery.fancytree-all-deps.js b/libraries/fancytree/jquery.fancytree-all-deps.jsindex 936ed0efcc..1398f9c6b1 100644--- a/libraries/fancytree/jquery.fancytree-all-deps.js+++ b/libraries/fancytree/jquery.fancytree-all-deps.js@@ -2986,7 +2986,7 @@ var uniqueId = $.fn.extend( {self = this,wasExpanded = this.isExpanded();- _assert(this.isLazy(), "load() requires a lazy node");+ //_assert(this.isLazy(), "load() requires a lazy node");// _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );if (!forceReload && !this.isUndefined()) {return _getResolvedPromise(this);diff --git a/src/public/app/services/tree_builder.js b/src/public/app/services/tree_builder.jsindex ddb90aeb70..d6eb09fc58 100644--- a/src/public/app/services/tree_builder.js+++ b/src/public/app/services/tree_builder.js@@ -21,12 +21,12 @@ async function prepareRootNode() {return await prepareNode(hoistedBranch);}-async function prepareBranch(note) {+async function prepareChildren(note) {if (note.type === 'search') {- return await prepareSearchBranch(note);+ return await prepareSearchNoteChildren(note);}else {- return await prepareRealBranch(note);+ return await prepareNormalNoteChildren(note);}}@@ -94,17 +94,24 @@ async function prepareNode(branch) {icon: getIcon(note),refKey: note.noteId,expanded: branch.isExpanded || hoistedNoteId === note.noteId,- lazy: true,key: utils.randomString(12) // this should prevent some "duplicate key" errors};- node.folder = getChildBranchesWithoutImages(note).length > 0- || note.type === 'search';+ const childBranches = getChildBranchesWithoutImages(note);++ node.folder = childBranches.length > 0+ || note.type === 'search'++ node.lazy = node.folder && !node.expanded;++ if (node.folder && node.expanded) {+ node.children = await prepareChildren(note);+ }return node;}-async function prepareRealBranch(parentNote) {+async function prepareNormalNoteChildren(parentNote) {utils.assertArguments(parentNote);const noteList = [];@@ -132,12 +139,12 @@ function getChildBranchesWithoutImages(parentNote) {return childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId));}-async function prepareSearchBranch(note) {+async function prepareSearchNoteChildren(note) {await treeCache.reloadNotes([note.noteId]);const newNote = await treeCache.getNote(note.noteId);- return await prepareRealBranch(newNote);+ return await prepareNormalNoteChildren(newNote);}function getExtraClasses(note) {@@ -174,7 +181,7 @@ function getExtraClasses(note) {export default {prepareRootNode,- prepareBranch,+ prepareBranch: prepareChildren,getExtraClasses,getIcon,getChildBranchesWithoutImagesdiff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.jsindex 8e76130348..278ad98a45 100644--- a/src/public/app/widgets/note_tree.js+++ b/src/public/app/widgets/note_tree.js@@ -220,7 +220,7 @@ export default class NoteTreeWidget extends TabAwareWidget {$span.append(refreshSearchButton);}},- // this is done to automatically lazy load all expanded search notes after tree load+ // this is done to automatically lazy load all expanded notes after tree loadloadChildren: (event, data) => {// semaphore since the conflict when two processes are trying to load the same data// breaks the fancytree@@ -441,12 +441,6 @@ export default class NoteTreeWidget extends TabAwareWidget {return list ? list : []; // if no nodes with this refKey are found, fancy tree returns null}- async reload() {- const rootNode = await treeBuilder.prepareRootNode();-- await this.tree.reload([rootNode]);- }-// must be event since it's triggered from outside the treecollapseTreeEvent() { this.collapseTree(); }@@ -637,7 +631,11 @@ export default class NoteTreeWidget extends TabAwareWidget {const activeNotePath = activeNode !== null ? treeService.getNotePath(activeNode) : null;- await this.reload();+ const rootNode = await treeBuilder.prepareRootNode();++ await this.batchUpdate(async () => {+ await this.tree.reload([rootNode]);+ });if (activeNotePath) {const node = await this.getNodeFromPath(activeNotePath, true);diff --git a/src/views/desktop.ejs b/src/views/desktop.ejsindex dd387edf2a..e56e4ad0d4 100644--- a/src/views/desktop.ejs+++ b/src/views/desktop.ejs@@ -64,7 +64,7 @@<!-- Include Fancytree skin and library --><link href="libraries/fancytree/skin-win8/ui.fancytree.min.css" rel="stylesheet">-<script src="libraries/fancytree/jquery.fancytree-all-deps.min.js"></script>+<script src="libraries/fancytree/jquery.fancytree-all-deps.js"></script><script src="libraries/jquery.hotkeys.js"></script><script src="libraries/jquery.fancytree.hotkeys.js"></script>