diff --git a/package-lock.json b/package-lock.json index 5fc034b7d..2472c90c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2801,9 +2801,9 @@ } }, "dayjs": { - "version": "1.8.34", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.34.tgz", - "integrity": "sha512-Olb+E6EoMvdPmAMq2QoucuyZycKHjTlBXmRx8Ada+wGtq4SIXuDCdtoaX4KkK0yjf1fJLnwXQURr8gQKWKaybw==" + "version": "1.8.35", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.35.tgz", + "integrity": "sha512-isAbIEenO4ilm6f8cpqvgjZCsuerDAz2Kb7ri201AiNn58aqXuaLJEnCtfIMdCvERZHNGRY5lDMTr/jdAnKSWQ==" }, "debug": { "version": "4.1.1", @@ -3104,9 +3104,9 @@ } }, "electron": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/electron/-/electron-9.2.1.tgz", - "integrity": "sha512-ZsetaQjXB8+9/EFW1FnfK4ukpkwXCxMEaiKiUZhZ0ZLFlLnFCpe0Bg4vdDf7e4boWGcnlgN1jAJpBw7w0eXuqA==", + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/electron/-/electron-9.3.0.tgz", + "integrity": "sha512-7zPLEZ+kOjVJqfawMQ0vVuZZRqvZIeiID3tbjjbVybbxXIlFMpZ2jogoh7PV3rLrtm+dKRfu7Qc4E7ob1d0FqQ==", "dev": true, "requires": { "@electron/get": "^1.0.1", diff --git a/package.json b/package.json index 5810633f6..4b12b9eac 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "commonmark": "0.29.1", "cookie-parser": "1.4.5", "csurf": "1.11.0", - "dayjs": "1.8.34", + "dayjs": "1.8.35", "debug": "4.1.1", "ejs": "3.1.5", "electron-debug": "3.1.0", diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js index 6fa8ca937..9f8c5b483 100644 --- a/src/services/note_cache/entities/note.js +++ b/src/services/note_cache/entities/note.js @@ -6,6 +6,33 @@ class Note { constructor(noteCache, row) { /** @param {NoteCache} */ this.noteCache = noteCache; + + this.update(row); + + /** @param {Branch[]} */ + this.parentBranches = []; + /** @param {Note[]} */ + this.parents = []; + /** @param {Note[]} */ + this.children = []; + /** @param {Attribute[]} */ + this.ownedAttributes = []; + + /** @param {Attribute[]|null} */ + this.attributeCache = null; + /** @param {Attribute[]|null} */ + this.inheritableAttributeCache = null; + + /** @param {Attribute[]} */ + this.targetRelations = []; + + this.noteCache.notes[this.noteId] = this; + + /** @param {Note[]|null} */ + this.ancestorCache = null; + } + + update(row) { /** @param {string} */ this.noteId = row.noteId; /** @param {string} */ @@ -26,34 +53,11 @@ class Note { this.isProtected = !!row.isProtected; /** @param {boolean} */ this.isDecrypted = !row.isProtected || !!row.isContentAvailable; - /** @param {Branch[]} */ - this.parentBranches = []; - /** @param {Note[]} */ - this.parents = []; - /** @param {Note[]} */ - this.children = []; - /** @param {Attribute[]} */ - this.ownedAttributes = []; - /** @param {Attribute[]|null} */ - this.attributeCache = null; - /** @param {Attribute[]|null} */ - this.inheritableAttributeCache = null; - - /** @param {Attribute[]} */ - this.targetRelations = []; + this.decrypt(); /** @param {string|null} */ this.flatTextCache = null; - - this.noteCache.notes[this.noteId] = this; - - if (protectedSessionService.isProtectedSessionAvailable()) { - this.decrypt(); - } - - /** @param {Note[]|null} */ - this.ancestorCache = null; } /** @return {Attribute[]} */ diff --git a/src/services/note_cache/note_cache_loader.js b/src/services/note_cache/note_cache_loader.js index 499fffb34..6129bf07f 100644 --- a/src/services/note_cache/note_cache_loader.js +++ b/src/services/note_cache/note_cache_loader.js @@ -31,7 +31,7 @@ function load() { } eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_SYNCED], ({entityName, entity}) => { - // note that entity can also be just POJO without methods if coming FROM entity_changes + // note that entity can also be just POJO without methods if coming from sync if (!noteCache.loaded) { return; @@ -44,15 +44,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED delete noteCache.notes[noteId]; } else if (noteId in noteCache.notes) { - const note = noteCache.notes[noteId]; - - // we can assume we have protected session since we managed to update - note.title = entity.title; - note.isProtected = entity.isProtected; - note.isDecrypted = !entity.isProtected || !!entity.isContentAvailable; - note.flatTextCache = null; - - note.decrypt(); + noteCache.notes[noteId].update(entity); } else { const note = new Note(noteCache, entity); diff --git a/src/services/search/expressions/note_cache_flat_text.js b/src/services/search/expressions/note_cache_flat_text.js index 024c5f5be..bbb5cbcea 100644 --- a/src/services/search/expressions/note_cache_flat_text.js +++ b/src/services/search/expressions/note_cache_flat_text.js @@ -84,9 +84,7 @@ class NoteCacheFlatTextExp extends Expression { const foundAttrTokens = []; for (const token of this.tokens) { - // not clear why, but sometimes note.type or note.mime is undefined - if ((note.type && note.type.includes(token)) - || (note.mime && note.mime.includes(token))) { + if (note.type.includes(token) || note.mime.includes(token)) { foundAttrTokens.push(token); } diff --git a/src/services/sync.js b/src/services/sync.js index da3b57af6..30976a5e4 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -37,11 +37,11 @@ async function sync() { do { const syncContext = await login(); - await pushSync(syncContext); + await pushChanges(syncContext); - await pullSync(syncContext); + await pullChanges(syncContext); - await pushSync(syncContext); + await pushChanges(syncContext); await syncFinished(syncContext); @@ -122,7 +122,7 @@ async function doLogin() { return syncContext; } -async function pullSync(syncContext) { +async function pullChanges(syncContext) { let atLeastOnePullApplied = false; while (true) { @@ -175,7 +175,7 @@ async function pullSync(syncContext) { log.info("Finished pull"); } -async function pushSync(syncContext) { +async function pushChanges(syncContext) { let lastSyncedPush = getLastSyncedPush(); while (true) {