mirror of
https://github.com/laurent22/joplin.git
synced 2026-03-13 08:09:59 +08:00
Server: Fix delta API can return changes in wrong order (#14713)
This commit is contained in:
@@ -51,17 +51,17 @@ describe('ChangeModel', () => {
|
||||
expect(allUncompressedChanges.length).toBe(8);
|
||||
|
||||
{
|
||||
// When we get all the changes, we get DELETE 1, CREATE 2, and CREATE 3:
|
||||
// When we get all the changes, we get CREATE 2, DELETE 1, and CREATE 3:
|
||||
// - We don't get CREATE 1 since CREATE 1 -> DELETE 1 was compressed to
|
||||
// DELETE 1.
|
||||
// - We don't get any UPDATE event since they've been compressed
|
||||
// down to the CREATE events.
|
||||
const changes = (await changeModel.delta(user.id)).items;
|
||||
expect(changes.length).toBe(3);
|
||||
expect(changes[0].item_id).toBe(item1.id);
|
||||
expect(changes[0].type).toBe(ChangeType.Delete);
|
||||
expect(changes[1].item_id).toBe(item2.id);
|
||||
expect(changes[1].type).toBe(ChangeType.Create);
|
||||
expect(changes[0].item_id).toBe(item2.id);
|
||||
expect(changes[0].type).toBe(ChangeType.Create);
|
||||
expect(changes[1].item_id).toBe(item1.id);
|
||||
expect(changes[1].type).toBe(ChangeType.Delete);
|
||||
expect(changes[2].item_id).toBe(item3.id);
|
||||
expect(changes[2].type).toBe(ChangeType.Create);
|
||||
}
|
||||
|
||||
@@ -282,10 +282,6 @@ export default class ChangeModel extends BaseModel<Change> {
|
||||
// returns the rows directly;
|
||||
const output: Change[] = results.rows ? results.rows : results;
|
||||
|
||||
// This property is present only for the purpose of ordering the results
|
||||
// and can be removed afterwards.
|
||||
for (const change of output) delete change.counter;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -324,6 +320,10 @@ export default class ChangeModel extends BaseModel<Change> {
|
||||
return deltaChange;
|
||||
});
|
||||
|
||||
// This property is present only for the purpose of ordering the results
|
||||
// and can be removed afterwards.
|
||||
for (const change of finalChanges) delete change.counter;
|
||||
|
||||
return {
|
||||
items: finalChanges,
|
||||
// If we have changes, we return the ID of the latest changes from which delta sync can resume.
|
||||
|
||||
Reference in New Issue
Block a user