This commit is contained in:
zadam 2020-01-29 22:32:22 +01:00
parent b65631be7e
commit 48b401164a
5 changed files with 26 additions and 20 deletions

View File

@ -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 */

View File

@ -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} */

View File

@ -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} */

View File

@ -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});
}

View File

@ -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;
}
}