Fix potential CloudKit crash where the database record might not come back on a query
This commit is contained in:
parent
50508446bb
commit
cc69dd699f
@ -23,6 +23,18 @@ struct CloudKitArticleStatusUpdate {
|
|||||||
var statuses: [SyncStatus]
|
var statuses: [SyncStatus]
|
||||||
var article: Article?
|
var article: Article?
|
||||||
|
|
||||||
|
init?(articleID: String, statuses: [SyncStatus], article: Article?) {
|
||||||
|
self.articleID = articleID
|
||||||
|
self.statuses = statuses
|
||||||
|
self.article = article
|
||||||
|
|
||||||
|
let rec = record
|
||||||
|
// This is an invalid status update. The article is required for new and all
|
||||||
|
if article == nil && (rec == .all || rec == .new) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var record: Record {
|
var record: Record {
|
||||||
if statuses.contains(where: { $0.key == .deleted }) {
|
if statuses.contains(where: { $0.key == .deleted }) {
|
||||||
return .delete
|
return .delete
|
||||||
|
@ -110,14 +110,14 @@ private extension CloudKitSendStatusOperation {
|
|||||||
let articlesDict = articles.reduce(into: [String: Article]()) { result, article in
|
let articlesDict = articles.reduce(into: [String: Article]()) { result, article in
|
||||||
result[article.articleID] = article
|
result[article.articleID] = article
|
||||||
}
|
}
|
||||||
let statusUpdates = syncStatusesDict.map { (key, value) in
|
let statusUpdates = syncStatusesDict.compactMap { (key, value) in
|
||||||
return CloudKitArticleStatusUpdate(articleID: key, statuses: value, article: articlesDict[key])
|
return CloudKitArticleStatusUpdate(articleID: key, statuses: value, article: articlesDict[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
articlesZone.modifyArticles(statusUpdates) { result in
|
articlesZone.modifyArticles(statusUpdates) { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success:
|
case .success:
|
||||||
self.database.deleteSelectedForProcessing(syncStatuses.map({ $0.articleID })) { _ in
|
self.database.deleteSelectedForProcessing(statusUpdates.map({ $0.articleID })) { _ in
|
||||||
// Don't clear the last one since we might have had additional ticks added
|
// Don't clear the last one since we might have had additional ticks added
|
||||||
if self.showProgress && self.refreshProgress?.numberRemaining ?? 0 > 1 {
|
if self.showProgress && self.refreshProgress?.numberRemaining ?? 0 > 1 {
|
||||||
self.refreshProgress?.completeTask()
|
self.refreshProgress?.completeTask()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user