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
fix sync / fulltext issue
zadam4b934a4a81b7
diff --git a/src/entities/note.js b/src/entities/note.jsindex fa43dbd135..c7451c1fdd 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 checkdiff --git a/src/services/note_fulltext.js b/src/services/note_fulltext.jsindex 8342a5a6f3..578541d137 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 ...