reloading notes after script changes

This commit is contained in:
zadam
2019-10-20 12:29:34 +02:00
parent 78f5b7b288
commit 2305ad7405
21 changed files with 115 additions and 82 deletions

View File

@@ -54,24 +54,27 @@ class TreeCache {
}
/**
* Reload children of given noteId.
* Reload notes and their children.
*/
async reloadChildren(noteId) {
const resp = await server.post('tree/load', { noteIds: [noteId] });
async reloadNotesAndTheirChildren(noteIds) {
// first load the data before clearing the cache
const resp = await server.post('tree/load', { noteIds });
for (const childNoteId of this.children[noteId] || []) {
this.parents[childNoteId] = this.parents[childNoteId].filter(p => p !== noteId);
for (const noteId of noteIds) {
for (const childNoteId of this.children[noteId] || []) {
this.parents[childNoteId] = this.parents[childNoteId].filter(p => p !== noteId);
const branchId = this.getBranchIdByChildParent(childNoteId, noteId);
const branchId = this.getBranchIdByChildParent(childNoteId, noteId);
delete this.branches[branchId];
delete this.childParentToBranch[childNoteId + '-' + noteId];
delete this.branches[branchId];
delete this.childParentToBranch[childNoteId + '-' + noteId];
}
this.children[noteId] = [];
delete this.notes[noteId];
}
this.children[noteId] = [];
delete this.notes[noteId];
this.addResp(resp.notes, resp.branches, resp.relations);
}
@@ -83,12 +86,10 @@ class TreeCache {
// to be able to find parents we need first to make sure it is actually loaded
await this.getNote(noteId);
for (const parentNoteId of this.parents[noteId] || []) {
await this.reloadChildren(parentNoteId);
}
await this.reloadNotesAndTheirChildren(this.parents[noteId] || []);
// this is done to load the new parents for the noteId
await this.reloadChildren(noteId);
await this.reloadNotesAndTheirChildren([noteId]);
}
/** @return {Promise<NoteShort[]>} */