From 145161ed8aff67976b19a483983de0a46d87108c Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 23 Feb 2021 17:59:19 -0600 Subject: [PATCH] Modify CloudKit add logic so that we don't wait to sync the statuses before completing the process. Fixes #2827 --- .../CloudKit/CloudKitAccountDelegate.swift | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 160c5e8c9..15aeebfeb 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -636,7 +636,9 @@ private extension CloudKitAccountDelegate { account.update(urlString, with: parsedItems) { result in switch result { case .success: - self.sendNewArticlesToTheCloud(account, feed, completion: completion) + self.sendNewArticlesToTheCloud(account, feed) + self.refreshProgress.clear() + completion(.success(feed)) case .failure(let error): self.refreshProgress.completeTasks(2) completion(.failure(error)) @@ -708,7 +710,9 @@ private extension CloudKitAccountDelegate { switch result { case .success(let externalID): feed.externalID = externalID - self.sendNewArticlesToTheCloud(account, feed, completion: completion) + self.sendNewArticlesToTheCloud(account, feed) + self.refreshProgress.clear() + completion(.success(feed)) case .failure(let error): container.removeWebFeed(feed) self.refreshProgress.completeTasks(2) @@ -740,7 +744,7 @@ private extension CloudKitAccountDelegate { } } - func sendNewArticlesToTheCloud(_ account: Account, _ feed: WebFeed, completion: @escaping (Result) -> Void) { + func sendNewArticlesToTheCloud(_ account: Account, _ feed: WebFeed) { account.fetchArticlesAsync(.webFeed(feed)) { result in switch result { case .success(let articles): @@ -749,19 +753,14 @@ private extension CloudKitAccountDelegate { self.sendArticleStatus(for: account, showProgress: true) { result in switch result { case .success: - self.articlesZone.fetchChangesInZone() { _ in - self.refreshProgress.completeTask() - completion(.success(feed)) - } + self.articlesZone.fetchChangesInZone() { _ in } case .failure(let error): - self.refreshProgress.clear() - completion(.failure(error)) + os_log(.error, log: self.log, "CloudKit Feed send articles error: %@.", error.localizedDescription) } } } case .failure(let error): - self.refreshProgress.clear() - completion(.failure(error)) + os_log(.error, log: self.log, "CloudKit Feed send articles error: %@.", error.localizedDescription) } } }