Skip to content

Commit 8225fbf

Browse files
committed
Bump logical clock on record before starting push
1 parent 68dfbe0 commit 8225fbf

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Sources/ParseCareKit/ParseRemote.swift

+8-9
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ public class ParseRemote: OCKRemoteSynchronizable {
461461
// Push all revision records
462462
ParseRemote.queue.async {
463463
Task {
464-
let logicalClock = deviceKnowledge.clock(for: self.uuid)
464+
var updatedDeviceKnowledge = deviceKnowledge
465+
// Increment and merge Knowledge Vector
466+
updatedDeviceKnowledge.increment(clockFor: self.uuid)
467+
let logicalClock = updatedDeviceKnowledge.clock(for: self.uuid)
465468
self.notifyRevisionProgress(0,
466469
totalRecords: deviceRevisions.count)
467470

@@ -477,7 +480,7 @@ public class ParseRemote: OCKRemoteSynchronizable {
477480
if index == (deviceRevisions.count - 1) {
478481
self.finishedRevisions(parseClock: parseClock,
479482
cloudVector: cloudVector,
480-
localClock: deviceKnowledge,
483+
localClock: updatedDeviceKnowledge,
481484
completion: completion)
482485
}
483486
} catch {
@@ -509,17 +512,13 @@ public class ParseRemote: OCKRemoteSynchronizable {
509512
}
510513
}
511514

512-
func finishedRevisions(_ shouldIncrementCloudClock: Bool = true,
515+
func finishedRevisions(_ incrementedCloudClock: Bool = true,
513516
parseClock: PCKClock,
514517
cloudVector: OCKRevisionRecord.KnowledgeVector,
515518
localClock: OCKRevisionRecord.KnowledgeVector,
516519
completion: @escaping (Error?) -> Void) {
517520
Task {
518521
var updatedCloudVector = cloudVector
519-
if shouldIncrementCloudClock {
520-
// Increment and merge Knowledge Vector
521-
updatedCloudVector.increment(clockFor: self.uuid)
522-
}
523522
updatedCloudVector.merge(with: localClock)
524523

525524
guard let updatedClock = PCKClock.encodeVector(updatedCloudVector, for: parseClock) else {
@@ -529,8 +528,8 @@ public class ParseRemote: OCKRemoteSynchronizable {
529528
}
530529

531530
// If clocks incremented or new clock introduced, no need to save to Cloud.
532-
guard shouldIncrementCloudClock ||
533-
(!shouldIncrementCloudClock && cloudVector.uuids.count != updatedCloudVector.uuids.count) else {
531+
guard incrementedCloudClock ||
532+
(!incrementedCloudClock && cloudVector.uuids.count != updatedCloudVector.uuids.count) else {
534533
await self.remoteStatus.setNotSynchronzing()
535534
// Clocks not updated, no need to update cloud.
536535
if #available(iOS 14.0, watchOS 7.0, *) {

0 commit comments

Comments
 (0)