frontend attribute cache refactoring WIP

This commit is contained in:
zadam
2020-01-25 11:52:45 +01:00
parent 52a907651e
commit 60c908cd63
11 changed files with 102 additions and 116 deletions

View File

@@ -533,6 +533,37 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
}
syncDataListener({data}) {
const noteIdsToRefresh = new Set();
// this has the problem that the former parentNoteId might not be invalidated
// and the former location of the branch/note won't be removed.
data.filter(sync => sync.entityName === 'branches').forEach(sync => {
const branch = treeCache.getBranch(sync.entityId);
// we assume that the cache contains the old branch state and we add also the old parentNoteId
// so that the old parent can also be updated
noteIdsToRefresh.add(branch.parentNoteId);
noteIdsToRefresh.add(sync.parentNoteId);
});
data.filter(sync => sync.entityName === 'notes').forEach(sync => noteIdsToRefresh.add(sync.entityId));
data.filter(sync => sync.entityName === 'note_reordering').forEach(sync => noteIdsToRefresh.add(sync.entityId));
data.filter(sync => sync.entityName === 'attributes').forEach(sync => {
const note = treeCache.notes[sync.noteId];
if (note && note.__attributeCache) {
noteIdsToRefresh.add(sync.entityId);
}
});
if (noteIdsToRefresh.size > 0) {
appContext.trigger('reloadNotes', {noteIds: Array.from(noteIdsToRefresh)});
}
}
hoistedNoteChangedListener() {
this.reloadTreeListener();
}