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 { class Attribute {
constructor(treeCache, row) { constructor(treeCache, row) {
this.treeCache = treeCache; this.treeCache = treeCache;
this.update(row);
}
update(row) {
/** @param {string} attributeId */ /** @param {string} attributeId */
this.attributeId = row.attributeId; this.attributeId = row.attributeId;
/** @param {string} noteId */ /** @param {string} noteId */

View File

@ -2,6 +2,11 @@
class Branch { class Branch {
constructor(treeCache, row) { constructor(treeCache, row) {
this.treeCache = treeCache; this.treeCache = treeCache;
this.update(row);
}
update(row) {
/** @param {string} primary key */ /** @param {string} primary key */
this.branchId = row.branchId; this.branchId = row.branchId;
/** @param {string} */ /** @param {string} */

View File

@ -17,6 +17,11 @@ class NoteShort {
*/ */
constructor(treeCache, row, branches) { constructor(treeCache, row, branches) {
this.treeCache = treeCache; this.treeCache = treeCache;
this.update(row, branches);
}
update(row, branches) {
/** @param {string} */ /** @param {string} */
this.noteId = row.noteId; this.noteId = row.noteId;
/** @param {string} */ /** @param {string} */

View File

@ -232,10 +232,14 @@ class TreeCache {
// FIXME does not actually belong here // FIXME does not actually belong here
async processSyncRows(syncRows) { async processSyncRows(syncRows) {
const noteIdsToReload = [];
const loadResults = new LoadResults(this); 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 => { syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => {
noteIdsToReload.push(sync.parentNoteId); noteIdsToReload.push(sync.parentNoteId);
noteIdsToReload.push(sync.noteId); noteIdsToReload.push(sync.noteId);
@ -243,12 +247,6 @@ class TreeCache {
loadResults.addBranch(sync.entityId, sync.sourceId); 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 => { syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => {
noteIdsToReload.push(sync.entityId); noteIdsToReload.push(sync.entityId);
@ -267,8 +265,6 @@ class TreeCache {
loadResults.addNoteRevision(sync.entityId, sync.noteId, sync.sourceId); loadResults.addNoteRevision(sync.entityId, sync.noteId, sync.sourceId);
}); });
await this.reloadNotes(noteIdsToReload);
const appContext = (await import('./app_context.js')).default; const appContext = (await import('./app_context.js')).default;
appContext.trigger('entitiesReloaded', {loadResults}); appContext.trigger('entitiesReloaded', {loadResults});
} }

View File

@ -74,20 +74,15 @@ function sendMessageToAllClients(message) {
async function fillInAdditionalProperties(sync) { async function fillInAdditionalProperties(sync) {
// fill in some extra data needed by the frontend // fill in some extra data needed by the frontend
if (sync.entityName === 'attributes') { if (sync.entityName === 'attributes') {
sync.noteId = await sql.getValue(`SELECT noteId sync.entity = await sql.getRow(`SELECT * FROM attributes WHERE attributeId = ?`, [sync.entityId]);
FROM attributes } else if (sync.entityName === 'branches') {
WHERE attributeId = ?`, [sync.entityId]); 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') { } else if (sync.entityName === 'note_revisions') {
sync.noteId = await sql.getValue(`SELECT noteId sync.noteId = await sql.getValue(`SELECT noteId
FROM note_revisions FROM note_revisions
WHERE noteRevisionId = ?`, [sync.entityId]); 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;
} }
} }