From ae8f4ffbbe1055a6008a2ff6fa088e4f25790d44 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 11 Apr 2019 21:44:35 +0200 Subject: [PATCH] minor sync fix for fulltext --- src/entities/note.js | 8 ++++---- src/services/note_fulltext.js | 5 +++++ src/services/sync_update.js | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 9253644fa..fa43dbd13 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -107,6 +107,10 @@ class Note extends Entity { /** @returns {Promise} */ async setContent(content) { + // force updating note itself so that dateChanged is represented correctly even for the content + this.forcedChange = true; + await this.save(); + this.content = content; const pojo = { @@ -128,10 +132,6 @@ class Note extends Entity { await sql.upsert("note_contents", "noteId", pojo); await syncTableService.addNoteContentSync(this.noteId); - - this.forcedChange = true; - - await this.save(); } /** @returns {Promise} */ diff --git a/src/services/note_fulltext.js b/src/services/note_fulltext.js index 3aa373746..8342a5a6f 100644 --- a/src/services/note_fulltext.js +++ b/src/services/note_fulltext.js @@ -5,6 +5,11 @@ const html2plaintext = require('html2plaintext'); const noteIdQueue = []; async function updateNoteFulltext(note) { + if (!note) { + // this might happen when note content is being synced before note itself + return; + } + if (note.isDeleted || note.isProtected || await note.hasLabel('archived')) { await sql.execute(`DELETE FROM note_fulltext diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 28636927a..7221318da 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -78,10 +78,10 @@ async function updateNoteContent(entity, sourceId) { await sql.replace("note_contents", entity); await syncTableService.addNoteContentSync(entity.noteId, sourceId); - - noteFulltextService.triggerNoteFulltextUpdate(entity.noteId); }); + noteFulltextService.triggerNoteFulltextUpdate(entity.noteId); + log.info("Update/sync note content for noteId=" + entity.noteId); } }