From 21575d862b86d663caeb3b46bcd138a3abce4f07 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 29 Aug 2020 23:08:53 +0200 Subject: [PATCH] attempt to fix consistency issue bug which caused synced note_contents to have NULL content when original is empty string --- src/services/handlers.js | 6 +++++- src/services/sync_update.js | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/services/handlers.js b/src/services/handlers.js index 8f5baafa9..5fad5bc03 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -66,7 +66,11 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) => return; } - note.setContent(targetNote.getContent()); + const targetNoteContent = targetNote.getContent(); + + if (targetNoteContent) { + note.setContent(targetNoteContent); + } } else if (entity.type === 'label' && entity.name === 'sorted') { treeService.sortNotesAlphabetically(entity.noteId); diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 79ff2bc6a..d00e1c47f 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -99,8 +99,15 @@ function updateNoteContent(remoteEntity, sourceId) { const localEntity = sql.getRow("SELECT * FROM note_contents WHERE noteId = ?", [remoteEntity.noteId]); if (shouldWeUpdateEntity(localEntity, remoteEntity)) { + // we always use Buffer object which is different from normal saving - there we use simple string type for "string notes" + // the problem is that in general it's not possible to whether a note_content is string note or note (syncs can arrive out of order) remoteEntity.content = remoteEntity.content === null ? null : Buffer.from(remoteEntity.content, 'base64'); + if (remoteEntity.content && remoteEntity.content.byteLength === 0) { + // there seems to be a bug which causes empty buffer to be stored as NULL which is then picked up as inconsistency + remoteEntity.content = ""; + } + sql.transactional(() => { sql.replace("note_contents", remoteEntity);