mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 05:15:59 +01:00
frontend attribute cache refactoring WIP
This commit is contained in:
@@ -2,6 +2,7 @@ import Branch from "../entities/branch.js";
|
||||
import NoteShort from "../entities/note_short.js";
|
||||
import ws from "./ws.js";
|
||||
import server from "./server.js";
|
||||
import Attribute from "../entities/attribute.js";
|
||||
|
||||
/**
|
||||
* TreeCache keeps a read only cache of note tree structure in frontend's memory.
|
||||
@@ -22,15 +23,18 @@ class TreeCache {
|
||||
|
||||
/** @type {Object.<string, Branch>} */
|
||||
this.branches = {};
|
||||
|
||||
/** @type {Object.<string, Attribute>} */
|
||||
this.attributes = {};
|
||||
}
|
||||
|
||||
load(noteRows, branchRows) {
|
||||
load(noteRows, branchRows, attributeRows) {
|
||||
this.init();
|
||||
|
||||
this.addResp(noteRows, branchRows);
|
||||
this.addResp(noteRows, branchRows, attributeRows);
|
||||
}
|
||||
|
||||
addResp(noteRows, branchRows) {
|
||||
addResp(noteRows, branchRows, attributeRows) {
|
||||
const branchesByNotes = {};
|
||||
|
||||
for (const branchRow of branchRows) {
|
||||
@@ -96,6 +100,28 @@ class TreeCache {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const attributeRow of attributeRows) {
|
||||
const {attributeId} = attributeRow;
|
||||
|
||||
this.attributes[attributeId] = new Attribute(this, attributeRow);
|
||||
|
||||
const note = this.notes[attributeRow.noteId];
|
||||
|
||||
if (!note.attributes.includes(attributeId)) {
|
||||
note.attributes.push(attributeId);
|
||||
}
|
||||
|
||||
if (attributeRow.type === 'relation') {
|
||||
const targetNote = this.notes[attributeRow.value];
|
||||
|
||||
if (targetNote) {
|
||||
if (!note.targetRelations.includes(attributeId)) {
|
||||
note.targetRelations.push(attributeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async reloadNotes(noteIds) {
|
||||
|
||||
Reference in New Issue
Block a user