mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
websocket events fill additional data from becca instead of database
This commit is contained in:
parent
f1338bb643
commit
a33661d050
@ -22,8 +22,6 @@ class Attribute {
|
|||||||
this.position = row.position;
|
this.position = row.position;
|
||||||
/** @param {boolean} isInheritable */
|
/** @param {boolean} isInheritable */
|
||||||
this.isInheritable = !!row.isInheritable;
|
this.isInheritable = !!row.isInheritable;
|
||||||
/** @param {boolean} */
|
|
||||||
this.isDeleted = !!row.isDeleted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {NoteShort} */
|
/** @returns {NoteShort} */
|
||||||
|
@ -21,8 +21,6 @@ class Branch {
|
|||||||
this.isExpanded = !!row.isExpanded;
|
this.isExpanded = !!row.isExpanded;
|
||||||
/** @param {boolean} */
|
/** @param {boolean} */
|
||||||
this.fromSearchNote = !!row.fromSearchNote;
|
this.fromSearchNote = !!row.fromSearchNote;
|
||||||
/** @param {boolean} */
|
|
||||||
this.isDeleted = !!row.isDeleted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {NoteShort} */
|
/** @returns {NoteShort} */
|
||||||
|
@ -6,6 +6,8 @@ const cls = require('./cls');
|
|||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const syncMutexService = require('./sync_mutex');
|
const syncMutexService = require('./sync_mutex');
|
||||||
const protectedSessionService = require('./protected_session');
|
const protectedSessionService = require('./protected_session');
|
||||||
|
const becca = require("../becca/becca");
|
||||||
|
const AbstractEntity = require("../becca/entities/abstract_entity.js");
|
||||||
|
|
||||||
let webSocketServer;
|
let webSocketServer;
|
||||||
let lastSyncedPush = null;
|
let lastSyncedPush = null;
|
||||||
@ -75,35 +77,61 @@ function sendMessageToAllClients(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fillInAdditionalProperties(entityChange) {
|
function fillInAdditionalProperties(entityChange) {
|
||||||
// most of these could be filled by becca
|
|
||||||
// the exception is isDeleted - in that case becca doesn't contain such entity at all
|
|
||||||
// this would have to be handled separately
|
|
||||||
|
|
||||||
if (entityChange.isErased) {
|
if (entityChange.isErased) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill in some extra data needed by the frontend
|
// fill in some extra data needed by the frontend
|
||||||
|
// first try to use becca which works for non-deleted entities
|
||||||
|
// only when that fails try to load from database
|
||||||
if (entityChange.entityName === 'attributes') {
|
if (entityChange.entityName === 'attributes') {
|
||||||
|
entityChange.entity = becca.getAttribute(entityChange.entityId);
|
||||||
|
|
||||||
|
if (!entityChange.entity) {
|
||||||
entityChange.entity = sql.getRow(`SELECT * FROM attributes WHERE attributeId = ?`, [entityChange.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM attributes WHERE attributeId = ?`, [entityChange.entityId]);
|
||||||
|
}
|
||||||
} else if (entityChange.entityName === 'branches') {
|
} else if (entityChange.entityName === 'branches') {
|
||||||
|
entityChange.entity = becca.getBranch(entityChange.entityId);
|
||||||
|
|
||||||
|
if (!entityChange.entity) {
|
||||||
entityChange.entity = sql.getRow(`SELECT * FROM branches WHERE branchId = ?`, [entityChange.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM branches WHERE branchId = ?`, [entityChange.entityId]);
|
||||||
|
}
|
||||||
} else if (entityChange.entityName === 'notes') {
|
} else if (entityChange.entityName === 'notes') {
|
||||||
|
entityChange.entity = becca.getNote(entityChange.entityId);
|
||||||
|
|
||||||
|
if (!entityChange.entity) {
|
||||||
entityChange.entity = sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [entityChange.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [entityChange.entityId]);
|
||||||
|
|
||||||
if (entityChange.entity.isProtected) {
|
if (entityChange.entity.isProtected) {
|
||||||
entityChange.entity.title = protectedSessionService.decryptString(entityChange.entity.title);
|
entityChange.entity.title = protectedSessionService.decryptString(entityChange.entity.title);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (entityChange.entityName === 'note_revisions') {
|
} else if (entityChange.entityName === 'note_revisions') {
|
||||||
entityChange.noteId = sql.getValue(`SELECT noteId
|
entityChange.noteId = sql.getValue(`SELECT noteId
|
||||||
FROM note_revisions
|
FROM note_revisions
|
||||||
WHERE noteRevisionId = ?`, [entityChange.entityId]);
|
WHERE noteRevisionId = ?`, [entityChange.entityId]);
|
||||||
} else if (entityChange.entityName === 'note_reordering') {
|
} else if (entityChange.entityName === 'note_reordering') {
|
||||||
entityChange.positions = sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [entityChange.entityId]);
|
entityChange.positions = {};
|
||||||
|
|
||||||
|
const parentNote = becca.getNote(entityChange.entityId);
|
||||||
|
|
||||||
|
if (parentNote) {
|
||||||
|
for (const childBranch of parentNote.getChildBranches()) {
|
||||||
|
entityChange.positions[childBranch.branchId] = childBranch.notePosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (entityChange.entityName === 'options') {
|
else if (entityChange.entityName === 'options') {
|
||||||
|
entityChange.entity = becca.getOption(entityChange.entityId);
|
||||||
|
|
||||||
|
if (!entityChange.entity) {
|
||||||
entityChange.entity = sql.getRow(`SELECT * FROM options WHERE name = ?`, [entityChange.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM options WHERE name = ?`, [entityChange.entityId]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityChange.entity instanceof AbstractEntity) {
|
||||||
|
entityChange.entity = entityChange.entity.getPojo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPing(client, entityChanges = []) {
|
function sendPing(client, entityChanges = []) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user