Chunk the new articles in advance of sending them to the zone so that we can count them in the progress bar.

This commit is contained in:
Maurice Parker 2020-04-26 14:05:57 -05:00
parent 2efa939f25
commit b168cef88b
1 changed files with 24 additions and 5 deletions

View File

@ -628,7 +628,30 @@ private extension CloudKitAccountDelegate {
self.articlesZone.deleteArticles(deletedArticles) { _ in
self.refreshProgress.completeTask()
self.articlesZone.saveNewArticles(newAndUpdatedArticles) { _ in
self.saveNewArticles(newAndUpdatedArticles) {
completion()
}
}
}
}
func saveNewArticles(_ articles: Set<Article>, 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()
@ -636,10 +659,6 @@ private extension CloudKitAccountDelegate {
}
}
}
}
func createProviderWebFeed(for account: Account, urlComponents: URLComponents, editedName: String?, container: Container, feedProvider: FeedProvider, completion: @escaping (Result<WebFeed, Error>) -> Void) {
refreshProgress.addToNumberOfTasksAndRemaining(5)