fix sync / fulltext issue

This commit is contained in:
zadam 2019-04-13 19:34:19 +02:00
parent 7e374e795b
commit 4b934a4a81
2 changed files with 18 additions and 6 deletions

View File

@ -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

View File

@ -19,14 +19,17 @@ async function updateNoteFulltext(note) {
let contentHash = null;
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') {
content = html2plaintext(content);
}
contentHash = note.contentHash;
}
}
// 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]);