From b168cef88bd83f2b4f9e8a2a4f4d5c0363af715c Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 26 Apr 2020 14:05:57 -0500 Subject: [PATCH] Chunk the new articles in advance of sending them to the zone so that we can count them in the progress bar. --- .../CloudKit/CloudKitAccountDelegate.swift | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift index 070fd05b7..c7cd0f13c 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift @@ -628,17 +628,36 @@ private extension CloudKitAccountDelegate { self.articlesZone.deleteArticles(deletedArticles) { _ in self.refreshProgress.completeTask() - self.articlesZone.saveNewArticles(newAndUpdatedArticles) { _ in - self.articlesZone.fetchChangesInZone() { _ in - self.refreshProgress.completeTask() - completion() - } + self.saveNewArticles(newAndUpdatedArticles) { + completion() } } } } + + func saveNewArticles(_ articles: Set
, completion: @escaping () -> Void) { + let group = DispatchGroup() + + let articleGroups = Array(articles).chunked(into: 300).map { Set($0) } + refreshProgress.addToNumberOfTasksAndRemaining(articleGroups.count) + + for articleGroup in articleGroups { + group.enter() + self.articlesZone.saveNewArticles(articleGroup) { _ in + self.refreshProgress.completeTask() + group.leave() + } + } + + group.notify(queue: DispatchQueue.main) { + self.articlesZone.fetchChangesInZone() { _ in + self.refreshProgress.completeTask() + completion() + } + } + } func createProviderWebFeed(for account: Account, urlComponents: URLComponents, editedName: String?, container: Container, feedProvider: FeedProvider, completion: @escaping (Result) -> Void) { refreshProgress.addToNumberOfTasksAndRemaining(5)