mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	fix sync / fulltext issue
This commit is contained in:
		
							parent
							
								
									7e374e795b
								
							
						
					
					
						commit
						4b934a4a81
					
				@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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]);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user