diff --git a/src/entities/note.js b/src/entities/note.js index fa43dbd13..c7451c1fd 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -72,10 +72,19 @@ class Note extends Entity { */ /** @returns {Promise<*>} */ - async getContent() { + async getContent(silentNotFoundError = false) { if (this.content === undefined) { const res = await sql.getRow(`SELECT content, hash FROM note_contents WHERE noteId = ?`, [this.noteId]); + if (!res) { + if (silentNotFoundError) { + return undefined; + } + else { + throw new Error("Cannot find note content for noteId=" + this.noteId); + } + } + this.content = res.content; this.contentHash = res.contentHash; // used only for note_fulltext consistency check diff --git a/src/services/note_fulltext.js b/src/services/note_fulltext.js index 8342a5a6f..578541d13 100644 --- a/src/services/note_fulltext.js +++ b/src/services/note_fulltext.js @@ -19,13 +19,16 @@ async function updateNoteFulltext(note) { let contentHash = null; if (['text', 'code'].includes(note.type)) { - content = await note.getContent(); + content = await note.getContent(true); - if (note.type === 'text' && note.mime === 'text/html') { - content = html2plaintext(content); + // might not be available during sync before note_contents is synced + if (content) { + if (note.type === 'text' && note.mime === 'text/html') { + content = html2plaintext(content); + } + + contentHash = note.contentHash; } - - contentHash = note.contentHash; } // optimistically try to update first ...