mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix sync / fulltext issue
This commit is contained in:
parent
7e374e795b
commit
4b934a4a81
@ -72,10 +72,19 @@ class Note extends Entity {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** @returns {Promise<*>} */
|
/** @returns {Promise<*>} */
|
||||||
async getContent() {
|
async getContent(silentNotFoundError = false) {
|
||||||
if (this.content === undefined) {
|
if (this.content === undefined) {
|
||||||
const res = await sql.getRow(`SELECT content, hash FROM note_contents WHERE noteId = ?`, [this.noteId]);
|
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.content = res.content;
|
||||||
this.contentHash = res.contentHash; // used only for note_fulltext consistency check
|
this.contentHash = res.contentHash; // used only for note_fulltext consistency check
|
||||||
|
|
||||||
|
@ -19,14 +19,17 @@ async function updateNoteFulltext(note) {
|
|||||||
let contentHash = null;
|
let contentHash = null;
|
||||||
|
|
||||||
if (['text', 'code'].includes(note.type)) {
|
if (['text', 'code'].includes(note.type)) {
|
||||||
content = await note.getContent();
|
content = await note.getContent(true);
|
||||||
|
|
||||||
|
// might not be available during sync before note_contents is synced
|
||||||
|
if (content) {
|
||||||
if (note.type === 'text' && note.mime === 'text/html') {
|
if (note.type === 'text' && note.mime === 'text/html') {
|
||||||
content = html2plaintext(content);
|
content = html2plaintext(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
contentHash = note.contentHash;
|
contentHash = note.contentHash;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// optimistically try to update first ...
|
// optimistically try to update first ...
|
||||||
const res = await sql.execute(`UPDATE note_fulltext SET title = ?, titleHash = ?, content = ?, contentHash = ? WHERE noteId = ?`, [note.title, note.hash, content, contentHash, note.noteId]);
|
const res = await sql.execute(`UPDATE note_fulltext SET title = ?, titleHash = ?, content = ?, contentHash = ? WHERE noteId = ?`, [note.title, note.hash, content, contentHash, note.noteId]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user