Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
implemented consistency check for note fulltext based on hashes
zadam946dae72d900
diff --git a/src/entities/note.js b/src/entities/note.jsindex a855a2d865..525d278be9 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 checkif (this.isProtected) {if (this.isContentAvailable) {diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 208fbc8a50..04e2cb135e 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.jsindex f1338baa11..3aa373746b 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 ...