Skip to content

Commit 94ff2f2

Browse files
committed
Use separate key for data
1 parent 192b400 commit 94ff2f2

5 files changed

Lines changed: 355 additions & 49 deletions

File tree

Sources/SQLiteData/CloudKit/CloudKit+StructuredQueries.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
get { self["\(key)_hash"] as? Data }
143143
set { self["\(key)_hash"] = newValue }
144144
}
145+
fileprivate subscript(data key: String) -> Data? {
146+
get { self["\(key)_data"] as? Data }
147+
set { self["\(key)_data"] = newValue }
148+
}
145149
}
146150

147151
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
@@ -178,8 +182,8 @@
178182
encryptedValues[hash: key] != hash
179183
else { return false }
180184

181-
if encryptedValues[key] != nil {
182-
encryptedValues.setObject(nil, forKey: key)
185+
if encryptedValues[data: key] != nil {
186+
encryptedValues[data: key] = nil
183187
}
184188
self[key] = newValue
185189
encryptedValues[hash: key] = hash
@@ -198,14 +202,16 @@
198202
else { return false }
199203

200204
if newValue.isSmall {
205+
let newData = Data(newValue)
201206
guard
202207
encryptedValues[at: key] <= userModificationTime,
203-
encryptedValues[key] != newValue
208+
encryptedValues[data: key] != newData
204209
else { return false }
205210
if self[key] != nil {
206-
self.setObject(nil, forKey: key)
211+
self[key] = nil
212+
encryptedValues[hash: key] = nil
207213
}
208-
encryptedValues[key] = newValue
214+
encryptedValues[data: key] = newData
209215
encryptedValues[at: key] = userModificationTime
210216
self.userModificationTime = userModificationTime
211217
return true
@@ -319,7 +325,7 @@
319325
switch Value(queryOutput: row[keyPath: keyPath]).queryBinding {
320326
case .blob(let value):
321327
if value.isSmall {
322-
return other.encryptedValues[key] != value
328+
return other.encryptedValues[key] != Data(value)
323329
} else if let otherHash = other.encryptedValues[hash: key] {
324330
return otherHash != value.sha256
325331
} else {

0 commit comments

Comments
 (0)