diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index d3b38278b..5c9153e39 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -689,10 +689,16 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, database.fetchStarredArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), completion: completion) } + /// Deprecated. Use fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate instead. public func fetchArticleIDsForStatusesWithoutArticles() throws -> Set { return try database.fetchArticleIDsForStatusesWithoutArticles() } + /// Fetch articleIDs for articles that we should have, but don’t. These articles are not userDeleted, and they are either (starred) or (unread and newer than the article cutoff date). + public func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) { + database.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(completion) + } + public func unreadCount(for webFeed: WebFeed) -> Int { return unreadCounts[webFeed.webFeedID] ?? 0 } diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 5966e5018..fa14f8cac 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -1127,53 +1127,56 @@ private extension FeedbinAccountDelegate { func refreshMissingArticles(_ account: Account, completion: @escaping ((Result) -> Void)) { os_log(.debug, log: log, "Refreshing missing articles...") - let group = DispatchGroup() - var errorOccurred = false - var fetchedArticleIDs = Set() - do { - fetchedArticleIDs = try account.fetchArticleIDsForStatusesWithoutArticles() - } - catch(let error) { - self.refreshProgress.completeTask() - completion(.failure(error)) - return - } + account.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate { result in + + switch result { + case .success(let fetchedArticleIDs): + + let group = DispatchGroup() + var errorOccurred = false + + let articleIDs = Array(fetchedArticleIDs) + let chunkedArticleIDs = articleIDs.chunked(into: 100) - let articleIDs = Array(fetchedArticleIDs) - let chunkedArticleIDs = articleIDs.chunked(into: 100) + for chunk in chunkedArticleIDs { + group.enter() + self.caller.retrieveEntries(articleIDs: chunk) { result in - for chunk in chunkedArticleIDs { - group.enter() - self.caller.retrieveEntries(articleIDs: chunk) { result in + switch result { + case .success(let entries): - switch result { - case .success(let entries): + self.processEntries(account: account, entries: entries) { error in + group.leave() + if error != nil { + errorOccurred = true + } + } - self.processEntries(account: account, entries: entries) { error in - group.leave() - if error != nil { + case .failure(let error): errorOccurred = true + os_log(.error, log: self.log, "Refresh missing articles failed: %@.", error.localizedDescription) + group.leave() } } - - case .failure(let error): - errorOccurred = true - os_log(.error, log: self.log, "Refresh missing articles failed: %@.", error.localizedDescription) - group.leave() } - } - } - group.notify(queue: DispatchQueue.main) { - self.refreshProgress.completeTask() - os_log(.debug, log: self.log, "Done refreshing missing articles.") - if errorOccurred { - completion(.failure(FeedbinAccountDelegateError.unknown)) - } else { - completion(.success(())) + group.notify(queue: DispatchQueue.main) { + self.refreshProgress.completeTask() + os_log(.debug, log: self.log, "Done refreshing missing articles.") + if errorOccurred { + completion(.failure(FeedbinAccountDelegateError.unknown)) + } else { + completion(.success(())) + } + } + + case .failure(let error): + completion(.failure(error)) } + } + } func refreshArticles(_ account: Account, page: String?, updateFetchDate: Date?, completion: @escaping ((Result) -> Void)) { diff --git a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift index f4b597594..646ad408d 100644 --- a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift +++ b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift @@ -182,7 +182,7 @@ public final class ArticlesDatabase { } /// Fetch articleIDs for articles that we should have, but don’t. These articles are not userDeleted, and they are either (starred) or (unread and newer than the article cutoff date). - func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) { + public func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) { articlesTable.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(completion) }