Skip to content

Commit

Permalink
Fix bug in shouldUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Nov 4, 2019
1 parent 66261fa commit 1af3292
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/core/datastore/core/changes-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,15 @@ export class ChangesStream {

private static shouldUpdate([documentAfterConflictResolution, squashRevisionIds]: [Document, Array<RevisionId>], latestRevisionDocument: Document) {

const resolvedDocumentStaff = documentAfterConflictResolution.resource[STAFF] || [];
const latestRevisionStaff = latestRevisionDocument.resource[STAFF] || [];

const resolvedDocumentCampaigns = documentAfterConflictResolution.resource[CAMPAIGNS] || [];
const latestRevisionCampaigns = latestRevisionDocument.resource[CAMPAIGNS] || [];

return squashRevisionIds.length > 0
// compare for length instead of equality, because we want to avoid loops where one machine reduces a length and then updates while another does the opposite
|| documentAfterConflictResolution.resource[STAFF].length > latestRevisionDocument.resource[STAFF].length
|| documentAfterConflictResolution.resource[CAMPAIGNS].length > latestRevisionDocument.resource[CAMPAIGNS].length;
|| resolvedDocumentStaff.length > latestRevisionStaff.length
|| resolvedDocumentCampaigns.length > latestRevisionCampaigns.length;
}
}

0 comments on commit 1af3292

Please sign in to comment.