Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Sources/SQLiteData/CloudKit/CloudKit+StructuredQueries.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
func update<T: PrimaryKeyedTable>(
with other: CKRecord,
row: T,
userModificationTime: Int64,
columnNames: inout [String],
parentForeignKey: ForeignKey?
) {
Expand Down Expand Up @@ -354,11 +355,17 @@
return false
}
}
if didSet || isRowValueModified {
if didSet {
columnNames.removeAll(where: { $0 == key })
if didSet, let parentForeignKey, key == parentForeignKey.from {
if let parentForeignKey, key == parentForeignKey.from {
self.parent = other.parent
}
} else if isRowValueModified {
let hasServerValueChanged = encryptedValues[at: key] > other.encryptedValues[at: key]
let isRowValueNewer = userModificationTime >= encryptedValues[at: key]
if !hasServerValueChanged || isRowValueNewer {
columnNames.removeAll(where: { $0 == key })
}
}
}
open(column)
Expand Down
1 change: 1 addition & 0 deletions Sources/SQLiteData/CloudKit/SyncEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,7 @@
serverRecord.update(
with: allFields,
row: T(queryOutput: row),
userModificationTime: metadata.userModificationTime,
columnNames: &columnNames,
parentForeignKey: foreignKeysByTableName[T.tableName]?.count == 1
? foreignKeysByTableName[T.tableName]?.first
Expand Down
7 changes: 4 additions & 3 deletions Tests/SQLiteDataTests/CloudKitTests/MergeConflictTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func serverRecordEditedAfterClientButProcessedBeforeClient() async throws {
@Test(.bug("https://github.com/pointfreeco/sqlite-data/issues/354"))
func serverRecordEditedAfterClientButProcessedBeforeClient() async throws {
try await userDatabase.userWrite { db in
try db.seed {
RemindersList(id: 1, title: "")
Expand Down Expand Up @@ -453,7 +454,7 @@
│ dueDate: nil, │
│ isCompleted: false, │
│ priority: nil, │
│ title: "Get milk", │
│ title: "Buy milk", │
│ remindersListID: 1 │
│ ) │
└───────────────────────┘
Expand All @@ -478,7 +479,7 @@
priority🗓️: 0,
remindersListID: 1,
remindersListID🗓️: 0,
title: "Get milk",
title: "Buy milk",
title🗓️: 60,
🗓️: 60
),
Expand Down
Loading