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

@@ -8,7 +8,14 @@ async function getNotesAndBranches(noteIds) {
noteIds = Array.from(new Set(noteIds));
const notes = await treeService.getNotes(noteIds);
noteIds = notes.map(n => n.noteId);
const noteMap = {};
noteIds = [];
for (const note of notes) {
note.attributes = [];
noteMap[note.noteId] = note;
noteIds.push(note.noteId);
}
// joining child note to filter out not completely synchronised notes which would then cause errors later
// cannot do that with parent because of root note's 'none' parent
@@ -28,6 +35,27 @@ async function getNotesAndBranches(noteIds) {
// sorting in memory is faster
branches.sort((a, b) => a.notePosition - b.notePosition < 0 ? -1 : 1);
const attributes = await sql.getManyRows(`
SELECT
noteId,
type,
name,
value,
isInheritable
FROM attributes
WHERE isDeleted = 0 AND noteId IN (???)`, noteIds);
for (const {noteId, type, name, value, isInheritable} of attributes) {
const note = noteMap[noteId];
note.attributes.push({
type,
name,
value,
isInheritable
});
}
return {
branches,
notes