From 268dfec554cba9c0a6842163517094556c58254b Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 17 Jul 2017 23:22:22 +0100 Subject: [PATCH] Fixed sync issue with conflicted notes --- CliClient/tests/synchronizer.js | 16 ++++++++++++++++ ReactNativeClient/lib/models/base-item.js | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CliClient/tests/synchronizer.js b/CliClient/tests/synchronizer.js index 4a8b5ec9c..206e27bd2 100644 --- a/CliClient/tests/synchronizer.js +++ b/CliClient/tests/synchronizer.js @@ -546,5 +546,21 @@ describe('Synchronizer', function() { done(); }); + + it('should not sync notes with conflicts', async (done) => { + let f1 = await Folder.save({ title: "folder" }); + let n1 = await Note.save({ title: "mynote", parent_id: f1.id, is_conflict: 1 }); + await synchronizer().start(); + + await switchClient(2); + + await synchronizer().start(); + let notes = await Note.all(); + let folders = await Folder.all() + expect(notes.length).toBe(0); + expect(folders.length).toBe(1); + + done(); + }); }); \ No newline at end of file diff --git a/ReactNativeClient/lib/models/base-item.js b/ReactNativeClient/lib/models/base-item.js index d39629340..e166d36e7 100644 --- a/ReactNativeClient/lib/models/base-item.js +++ b/ReactNativeClient/lib/models/base-item.js @@ -257,16 +257,21 @@ class BaseItem extends BaseModel { const fieldNames = ItemClass.fieldNames(true); fieldNames.push('sync_time'); + let extraWhere = className == 'Note' ? 'AND is_conflict = 0' : ''; + let sql = sprintf(` SELECT %s FROM %s LEFT JOIN sync_items t ON t.item_id = %s.id - WHERE t.id IS NULL OR t.sync_time < %s.updated_time + WHERE + (t.id IS NULL OR t.sync_time < %s.updated_time) + %s LIMIT %d `, this.db().escapeFields(fieldNames), this.db().escapeField(ItemClass.tableName()), this.db().escapeField(ItemClass.tableName()), this.db().escapeField(ItemClass.tableName()), + extraWhere, limit); const items = await ItemClass.modelSelectAll(sql);