Skip to content

Build your personal knowledge base with Trilium Notes

wip

zadam48b401164aa6
diff --git a/src/public/javascripts/entities/attribute.js b/src/public/javascripts/entities/attribute.js
index cff714908d..688b86d585 100644
--- a/src/public/javascripts/entities/attribute.js
+++ b/src/public/javascripts/entities/attribute.js
@@ -1,6 +1,11 @@
class Attribute {
constructor(treeCache, row) {
this.treeCache = treeCache;
+
+ this.update(row);
+ }
+
+ update(row) {
/** @param {string} attributeId */
this.attributeId = row.attributeId;
/** @param {string} noteId */
diff --git a/src/public/javascripts/entities/branch.js b/src/public/javascripts/entities/branch.js
index 21a4f1487f..b9c8798e12 100644
--- a/src/public/javascripts/entities/branch.js
+++ b/src/public/javascripts/entities/branch.js
@@ -2,6 +2,11 @@
class Branch {
constructor(treeCache, row) {
this.treeCache = treeCache;
+
+ this.update(row);
+ }
+
+ update(row) {
/** @param {string} primary key */
this.branchId = row.branchId;
/** @param {string} */
diff --git a/src/public/javascripts/entities/note_short.js b/src/public/javascripts/entities/note_short.js
index 6c727273d9..1f4645faed 100644
--- a/src/public/javascripts/entities/note_short.js
+++ b/src/public/javascripts/entities/note_short.js
@@ -17,6 +17,11 @@ class NoteShort {
*/
constructor(treeCache, row, branches) {
this.treeCache = treeCache;
+
+ this.update(row, branches);
+ }
+
+ update(row, branches) {
/** @param {string} */
this.noteId = row.noteId;
/** @param {string} */
diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.js
index 9fbdf43d77..ac1a267e6c 100644
--- a/src/public/javascripts/services/tree_cache.js
+++ b/src/public/javascripts/services/tree_cache.js
@@ -232,10 +232,14 @@ class TreeCache {
// FIXME does not actually belong here
async processSyncRows(syncRows) {
- const noteIdsToReload = [];
-
const loadResults = new LoadResults(this);
+ syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => {
+
+
+ loadResults.addNote(sync.entityId, sync.sourceId);
+ });
+
syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => {
noteIdsToReload.push(sync.parentNoteId);
noteIdsToReload.push(sync.noteId);
@@ -243,12 +247,6 @@ class TreeCache {
loadResults.addBranch(sync.entityId, sync.sourceId);
});
- syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => {
- noteIdsToReload.push(sync.entityId);
-
- loadResults.addNote(sync.entityId, sync.sourceId);
- });
-
syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => {
noteIdsToReload.push(sync.entityId);
@@ -267,8 +265,6 @@ class TreeCache {
loadResults.addNoteRevision(sync.entityId, sync.noteId, sync.sourceId);
});
- await this.reloadNotes(noteIdsToReload);
-
const appContext = (await import('./app_context.js')).default;
appContext.trigger('entitiesReloaded', {loadResults});
}
diff --git a/src/services/ws.js b/src/services/ws.js
index 6cc4a88d2a..b84d7f5bda 100644
--- a/src/services/ws.js
+++ b/src/services/ws.js
@@ -74,20 +74,15 @@ function sendMessageToAllClients(message) {
async function fillInAdditionalProperties(sync) {
// fill in some extra data needed by the frontend
if (sync.entityName === 'attributes') {
- sync.noteId = await sql.getValue(`SELECT noteId
- FROM attributes
- WHERE attributeId = ?`, [sync.entityId]);
+ sync.entity = await sql.getRow(`SELECT * FROM attributes WHERE attributeId = ?`, [sync.entityId]);
+ } else if (sync.entityName === 'branches') {
+ sync.entity = await sql.getRow(`SELECT * FROM branches WHERE branchId = ?`, [sync.entityId]);
+ } else if (sync.entityName === 'notes') {
+ sync.entity = await sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [sync.entityId]);
} else if (sync.entityName === 'note_revisions') {
sync.noteId = await sql.getValue(`SELECT noteId
FROM note_revisions
WHERE noteRevisionId = ?`, [sync.entityId]);
- } else if (sync.entityName === 'branches') {
- const {noteId, parentNoteId} = await sql.getRow(`SELECT noteId, parentNoteId
- FROM branches
- WHERE branchId = ?`, [sync.entityId]);
-
- sync.noteId = noteId;
- sync.parentNoteId = parentNoteId;
}
}