attempt to fix consistency issue bug which caused synced note_contents to have NULL content when original is empty string

This commit is contained in:
zadam 2020-08-29 23:08:53 +02:00
parent 9359f05335
commit 21575d862b
2 changed files with 12 additions and 1 deletions

View File

@ -66,7 +66,11 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) =>
return; return;
} }
note.setContent(targetNote.getContent()); const targetNoteContent = targetNote.getContent();
if (targetNoteContent) {
note.setContent(targetNoteContent);
}
} }
else if (entity.type === 'label' && entity.name === 'sorted') { else if (entity.type === 'label' && entity.name === 'sorted') {
treeService.sortNotesAlphabetically(entity.noteId); treeService.sortNotesAlphabetically(entity.noteId);

View File

@ -99,8 +99,15 @@ function updateNoteContent(remoteEntity, sourceId) {
const localEntity = sql.getRow("SELECT * FROM note_contents WHERE noteId = ?", [remoteEntity.noteId]); const localEntity = sql.getRow("SELECT * FROM note_contents WHERE noteId = ?", [remoteEntity.noteId]);
if (shouldWeUpdateEntity(localEntity, remoteEntity)) { 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'); 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.transactional(() => {
sql.replace("note_contents", remoteEntity); sql.replace("note_contents", remoteEntity);