load search result only on explicit action (expand node, execute search), #1759

This commit is contained in:
zadam 2021-03-18 21:05:43 +01:00
parent 59e8cb8c8b
commit 6edc6e2825
3 changed files with 39 additions and 35 deletions

View file

@ -164,8 +164,16 @@ class TreeCache {
this.addResp(resp);
for (const note of resp.notes) {
if (note.type === 'search') {
appContext.triggerEvent('notesReloaded', {noteIds});
}
async loadSearchNote(noteId) {
const note = await this.getNote(noteId);
if (!note || note.type !== 'search') {
return;
}
const searchResultNoteIds = await server.get('search-note/' + note.noteId);
if (!Array.isArray(searchResultNoteIds)) {
@ -178,7 +186,7 @@ class TreeCache {
treeCache.notes[note.noteId].childToBranch = {};
}
const branches = resp.branches.filter(b => b.noteId === note.noteId || b.parentNoteId === note.noteId);
const branches = [...note.getBranches(), ...note.getChildBranches()];
searchResultNoteIds.forEach((resultNoteId, index) => branches.push({
// branchId should be repeatable since sometimes we reload some notes without rerendering the tree
@ -198,10 +206,6 @@ class TreeCache {
treeCache.notes[note.noteId].searchResultsLoaded = true;
}
}
appContext.triggerEvent('notesReloaded', {noteIds});
}
/** @return {NoteShort[]} */
getNotesFromCache(noteIds, silentNotFoundError = false) {

View file

@ -472,7 +472,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
return;
}
data.result = treeCache.reloadNotes([noteId]).then(() => {
data.result = treeCache.loadSearchNote(noteId).then(() => {
const note = treeCache.getNoteFromCache(noteId);
let childNoteIds = note.getChildNoteIds();

View file

@ -265,7 +265,7 @@ export default class SearchDefinitionWidget extends TabAwareWidget {
async refreshResultsCommand() {
try {
await treeCache.reloadNotes([this.noteId]);
await treeCache.loadSearchNote(this.noteId);
}
catch (e) {
toastService.showError(e.message);