1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Fixed sync issue with conflicted notes

This commit is contained in:
Laurent Cozic 2017-07-17 23:22:22 +01:00
parent cd184e26d0
commit 268dfec554
2 changed files with 22 additions and 1 deletions

View File

@ -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();
});
});

View File

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