From 4cd1a0ee7dfb2ca2c46e5ed65a56f1ea8c31ab3c Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 27 Aug 2020 22:37:57 +0200 Subject: [PATCH] fix note cache for out of order synced entities --- .../0167__remove_activateParentNote.sql | 1 + src/services/app_info.js | 2 +- src/services/note_cache/entities/attribute.js | 8 +++++ src/services/note_cache/entities/branch.js | 30 +++++++++++-------- 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 db/migrations/0167__remove_activateParentNote.sql diff --git a/db/migrations/0167__remove_activateParentNote.sql b/db/migrations/0167__remove_activateParentNote.sql new file mode 100644 index 000000000..a16956905 --- /dev/null +++ b/db/migrations/0167__remove_activateParentNote.sql @@ -0,0 +1 @@ +DELETE FROM options WHERE name = 'keyboardShortcutsActivateParentNote'; diff --git a/src/services/app_info.js b/src/services/app_info.js index 627cd0baf..0771d2600 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -4,7 +4,7 @@ const build = require('./build'); const packageJson = require('../../package'); const {TRILIUM_DATA_DIR} = require('./data_dir'); -const APP_DB_VERSION = 166; +const APP_DB_VERSION = 167; const SYNC_VERSION = 16; const CLIPPER_PROTOCOL_VERSION = "1.0"; diff --git a/src/services/note_cache/entities/attribute.js b/src/services/note_cache/entities/attribute.js index a50b4df04..7fa412506 100644 --- a/src/services/note_cache/entities/attribute.js +++ b/src/services/note_cache/entities/attribute.js @@ -1,5 +1,7 @@ "use strict"; +import Note from './note.js'; + class Attribute { constructor(noteCache, row) { /** @param {NoteCache} */ @@ -23,6 +25,12 @@ class Attribute { this.isInheritable = !!row.isInheritable; this.noteCache.attributes[this.attributeId] = this; + + if (!(this.noteId in this.noteCache.notes)) { + // entities can come out of order in sync, create skeleton which will be filled later + this.noteCache.notes[this.noteId] = new Note(this.noteCache, {noteId: this.noteId}); + } + this.noteCache.notes[this.noteId].ownedAttributes.push(this); const key = `${this.type}-${this.name}`; diff --git a/src/services/note_cache/entities/branch.js b/src/services/note_cache/entities/branch.js index dfff5a393..dda388fe4 100644 --- a/src/services/note_cache/entities/branch.js +++ b/src/services/note_cache/entities/branch.js @@ -1,5 +1,7 @@ "use strict"; +import Note from "./note.js"; + class Branch { constructor(noteCache, row) { /** @param {NoteCache} */ @@ -17,14 +19,9 @@ class Branch { return; } - const childNote = this.noteCache.notes[this.noteId]; + const childNote = this.childNote; const parentNote = this.parentNote; - if (!childNote) { - console.log(`Cannot find child note ${this.noteId} of a branch ${this.branchId}`); - return; - } - childNote.parents.push(parentNote); childNote.parentBranches.push(this); @@ -35,14 +32,23 @@ class Branch { } /** @return {Note} */ - get parentNote() { - const note = this.noteCache.notes[this.parentNoteId]; - - if (!note) { - console.log(`Cannot find note ${this.parentNoteId}`); + get childNote() { + if (!(this.noteId in this.noteCache.notes)) { + // entities can come out of order in sync, create skeleton which will be filled later + this.noteCache.notes[this.noteId] = new Note(this.noteCache, {noteId: this.noteId}); } - return note; + return this.noteCache.notes[this.noteId]; + } + + /** @return {Note} */ + get parentNote() { + if (!(this.parentNoteId in this.noteCache.notes)) { + // entities can come out of order in sync, create skeleton which will be filled later + this.noteCache.notes[this.parentNoteId] = new Note(this.noteCache, {noteId: this.parentNoteId}); + } + + return this.noteCache.notes[this.parentNoteId]; } }