From 90d091aedb523dfd3528103e3238544160189b30 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 30 Apr 2020 23:58:34 +0200 Subject: [PATCH] make note tree initial load non-lazy --- .../fancytree/jquery.fancytree-all-deps.js | 2 +- src/public/app/services/tree_builder.js | 27 ++++++++++++------- src/public/app/widgets/note_tree.js | 14 +++++----- src/views/desktop.ejs | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/libraries/fancytree/jquery.fancytree-all-deps.js b/libraries/fancytree/jquery.fancytree-all-deps.js index 936ed0efc..1398f9c6b 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.js index ddb90aeb7..d6eb09fc5 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, getChildBranchesWithoutImages diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 8e7613034..278ad98a4 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 load loadChildren: (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 tree collapseTreeEvent() { 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.ejs index dd387edf2..e56e4ad0d 100644 --- a/src/views/desktop.ejs +++ b/src/views/desktop.ejs @@ -64,7 +64,7 @@ - +