diff --git a/src/entities/note.js b/src/entities/note.js index a855a2d86..525d278be 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -74,7 +74,10 @@ class Note extends Entity { /** @returns {Promise<*>} */ async getContent() { if (this.content === undefined) { - this.content = await sql.getValue(`SELECT content FROM note_contents WHERE noteId = ?`, [this.noteId]); + const res = await sql.getRow(`SELECT content, hash FROM note_contents WHERE noteId = ?`, [this.noteId]); + + this.content = res.content; + this.contentHash = res.contentHash; // used only for note_fulltext consistency check if (this.isProtected) { if (this.isContentAvailable) { diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 208fbc8a5..04e2cb135 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -5,6 +5,7 @@ const sqlInit = require('./sql_init'); const log = require('./log'); const messagingService = require('./messaging'); const syncMutexService = require('./sync_mutex'); +const noteFulltextService = require('./note_fulltext'); const repository = require('./repository'); const cls = require('./cls'); const syncTableService = require('./sync_table'); @@ -357,6 +358,24 @@ async function findLogicIssues() { logFix(`Removed link ${linkId} because target note ${targetNoteId} is also deleted.`); }); + + await findAndFixIssues(` + SELECT + noteId + FROM + notes + JOIN note_contents USING(noteId) + LEFT JOIN note_fulltext USING(noteId) + WHERE + notes.isDeleted = 0 + AND (note_fulltext.noteId IS NULL + OR note_fulltext.titleHash != notes.hash + OR note_fulltext.contentHash != note_contents.hash)`, + async ({noteId}) => { + noteFulltextService.triggerNoteFulltextUpdate(noteId); + + logFix(`Triggered fulltext update of note ${noteId} since it was out of sync.`); + }); } async function runSyncRowChecks(entityName, key) { diff --git a/src/services/note_fulltext.js b/src/services/note_fulltext.js index f1338baa1..3aa373746 100644 --- a/src/services/note_fulltext.js +++ b/src/services/note_fulltext.js @@ -20,8 +20,7 @@ async function updateNoteFulltext(note) { content = html2plaintext(content); } - // FIXME - //contentHash = noteContent.hash; + contentHash = note.contentHash; } // optimistically try to update first ...