mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-09 08:23:42 +01:00
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 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 {
|
||||
if statuses.contains(where: { $0.key == .deleted }) {
|
||||
return .delete
|
||||
|
@ -110,14 +110,14 @@ private extension CloudKitSendStatusOperation {
|
||||
let articlesDict = articles.reduce(into: [String: Article]()) { result, article in
|
||||
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])
|
||||
}
|
||||
|
||||
articlesZone.modifyArticles(statusUpdates) { result in
|
||||
switch result {
|
||||
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
|
||||
if self.showProgress && self.refreshProgress?.numberRemaining ?? 0 > 1 {
|
||||
self.refreshProgress?.completeTask()
|
||||
|
Loading…
Reference in New Issue
Block a user