diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 62d63c01d..7834f8252 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -624,7 +624,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, public func fetchArticles(_ fetchType: FetchType) throws -> Set
{ switch fetchType { case .starred: - return fetchStarredArticles() + return try fetchStarredArticles() case .unread: return try fetchUnreadArticles() case .today: @@ -784,7 +784,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, /// Update statuses specified by articleIDs — set a key and value. /// This updates the database, and sends a .StatusesDidChange notification. /// Any statuses that don’t exist will be automatically created. - func mark(articleIDs: Set, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping DatabaseCompletionBlock? = nil) { + func mark(articleIDs: Set, statusKey: ArticleStatus.Key, flag: Bool, completion: DatabaseCompletionBlock? = nil) { // TODO } @@ -853,7 +853,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, public func debugRunSearch() { #if DEBUG let t1 = Date() - let articles = fetchArticlesMatching("Brent NetNewsWire") + let articles = try! fetchArticlesMatching("Brent NetNewsWire") let t2 = Date() print(t2.timeIntervalSince(t1)) print(articles.count) @@ -940,8 +940,8 @@ extension Account: WebFeedMetadataDelegate { private extension Account { - func fetchStarredArticles() -> Set
{ - return database.fetchStarredArticles(flattenedWebFeeds().webFeedIDs()) + func fetchStarredArticles() throws -> Set
{ + return try database.fetchStarredArticles(flattenedWebFeeds().webFeedIDs()) } func fetchStarredArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { @@ -987,9 +987,14 @@ private extension Account { } func fetchArticlesAsync(webFeed: WebFeed, _ completion: @escaping ArticleSetResultBlock) { - database.fetchArticlesAsync(webFeed.webFeedID) { [weak self] (articles) in - self?.validateUnreadCount(webFeed, articles) - completion(articles) + database.fetchArticlesAsync(webFeed.webFeedID) { [weak self] articleSetResult in + switch articleSetResult { + case .success(let articles): + self?.validateUnreadCount(webFeed, articles) + completion(.success(articles)) + case .failure(let databaseError): + completion(.failure(databaseError)) + } } } @@ -1040,9 +1045,14 @@ private extension Account { func fetchArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetResultBlock) { let webFeeds = container.flattenedWebFeeds() - database.fetchArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in - self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) - completion(articles) + database.fetchArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articleSetResult) in + switch articleSetResult { + case .success(let articles): + self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) + completion(.success(articles)) + case .failure(let databaseError): + completion(.failure(databaseError)) + } } } @@ -1055,9 +1065,14 @@ private extension Account { func fetchUnreadArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetResultBlock) { let webFeeds = container.flattenedWebFeeds() - database.fetchUnreadArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in - self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) - completion(articles) + database.fetchUnreadArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articleSetResult) in + switch articleSetResult { + case .success(let articles): + self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) + completion(.success(articles)) + case .failure(let databaseError): + completion(.failure(databaseError)) + } } } diff --git a/Frameworks/Account/AccountManager.swift b/Frameworks/Account/AccountManager.swift index f3badd13d..8183e68d3 100644 --- a/Frameworks/Account/AccountManager.swift +++ b/Frameworks/Account/AccountManager.swift @@ -9,6 +9,7 @@ import Foundation import RSCore import Articles +import ArticlesDatabase // Main thread only. @@ -255,17 +256,17 @@ public final class AccountManager: UnreadCountProvider { // These fetch articles from active accounts and return a merged Set
. - public func fetchArticles(_ fetchType: FetchType) -> Set
{ + public func fetchArticles(_ fetchType: FetchType) throws -> Set
{ precondition(Thread.isMainThread) var articles = Set
() for account in activeAccounts { - articles.formUnion(account.fetchArticles(fetchType)) + articles.formUnion(try account.fetchArticles(fetchType)) } return articles } - public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetBlock) { + public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetResultBlock) { precondition(Thread.isMainThread) var allFetchedArticles = Set
() @@ -273,11 +274,18 @@ public final class AccountManager: UnreadCountProvider { var accountsReporting = 0 for account in activeAccounts { - account.fetchArticlesAsync(fetchType) { (articles) in - allFetchedArticles.formUnion(articles) + account.fetchArticlesAsync(fetchType) { (articleSetResult) in accountsReporting += 1 - if accountsReporting == numberOfAccounts { - completion(allFetchedArticles) + + switch articleSetResult { + case .success(let articles): + allFetchedArticles.formUnion(articles) + if accountsReporting == numberOfAccounts { + completion(.success(allFetchedArticles)) + } + case .failure(let databaseError): + completion(.failure(databaseError)) + return } } }