Skip to content

Commit

Permalink
Only check server clock on LiveQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed Apr 21, 2023
1 parent 8434c6f commit 4eba1e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/ParseCareKit/Models/RemoteSynchronizing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ actor RemoteSynchronizing {
knowledgeVector = vector
}

func hasNewerRevision(_ vector: OCKRevisionRecord.KnowledgeVector) -> Bool {
func hasNewerRevision(_ vector: OCKRevisionRecord.KnowledgeVector, for uuid: UUID) -> Bool {
guard !isSynchronizing else {
return false
}
guard let knowledgeVector = knowledgeVector else {
guard let currentClock = knowledgeVector?.clock(for: uuid) else {
return true
}
return vector >= knowledgeVector
return vector.clock(for: uuid) > currentClock
}
}
7 changes: 3 additions & 4 deletions Sources/ParseCareKit/ParseRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public class ParseRemote: OCKRemoteSynchronizable {
do {
let updatedVector = try PCKClock.decodeVector(updatedClock)
Task {
guard await self.remoteStatus.hasNewerRevision(updatedVector) else {
guard await self.remoteStatus.hasNewerRevision(updatedVector, for: self.uuid) else {
return
}
self.parseDelegate?.didRequestSynchronization(self)
Expand Down Expand Up @@ -349,7 +349,7 @@ public class ParseRemote: OCKRemoteSynchronizable {
return
}

guard await !self.remoteStatus.hasNewerRevision(parseVector) else {
guard await !self.remoteStatus.hasNewerRevision(parseVector, for: self.uuid) else {
let errorString = "New knowledge on server. Pull first then try again"
Logger.pushRevisions.error("\(errorString)")
await self.remoteStatus.notSynchronzing()
Expand Down Expand Up @@ -412,8 +412,7 @@ public class ParseRemote: OCKRemoteSynchronizable {
updatedParseVector = incrementVectorClock(updatedParseVector)
}
updatedParseVector.merge(with: localClock)
guard (shouldIncrementClock || (!shouldIncrementClock && updatedParseVector.uuids.count > parseVector.uuids.count)),
let updatedClock = PCKClock.encodeVector(updatedParseVector, for: parseClock) else {
guard let updatedClock = PCKClock.encodeVector(updatedParseVector, for: parseClock) else {
await self.remoteStatus.updateKnowledgeVector(parseVector) // revert
await self.remoteStatus.notSynchronzing()
completion(ParseCareKitError.couldntUnwrapClock)
Expand Down

0 comments on commit 4eba1e3

Please sign in to comment.