diff --git a/Account/Sources/Account/ArticleFetcher.swift b/Account/Sources/Account/ArticleFetcher.swift index 8d8e343ce..236693f9b 100644 --- a/Account/Sources/Account/ArticleFetcher.swift +++ b/Account/Sources/Account/ArticleFetcher.swift @@ -16,7 +16,6 @@ public protocol ArticleFetcher { @MainActor func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) @MainActor func fetchUnreadArticles() async throws -> Set
- @MainActor func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) } extension Feed: ArticleFetcher { @@ -49,22 +48,6 @@ extension Feed: ArticleFetcher { return try await account.unreadArticles(feed: self) } - - public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - guard let account = account else { - assertionFailure("Expected feed.account, but got nil.") - completion(.success(Set
())) - return - } - account.fetchArticlesAsync(.feed(self)) { articleSetResult in - switch articleSetResult { - case .success(let articles): - completion(.success(articles.unreadArticles())) - case .failure(let error): - completion(.failure(error)) - } - } - } } extension Folder: ArticleFetcher { @@ -89,17 +72,6 @@ extension Folder: ArticleFetcher { try await articles(unreadOnly: true) } - - public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - guard let account else { - assertionFailure("Expected folder.account, but got nil.") - completion(.success(Set
())) - return - } - - account.fetchArticlesAsync(.folder(self, true), completion) - } } private extension Folder { diff --git a/Shared/SmartFeeds/SmartFeed.swift b/Shared/SmartFeeds/SmartFeed.swift index a80b1efc3..64bfcd760 100644 --- a/Shared/SmartFeeds/SmartFeed.swift +++ b/Shared/SmartFeeds/SmartFeed.swift @@ -103,11 +103,6 @@ extension SmartFeed: ArticleFetcher { try await delegate.fetchUnreadArticles() } - - func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - delegate.fetchUnreadArticlesAsync(completion) - } } private extension SmartFeed { diff --git a/Shared/SmartFeeds/UnreadFeed.swift b/Shared/SmartFeeds/UnreadFeed.swift index 0ece229c3..bd13f3a25 100644 --- a/Shared/SmartFeeds/UnreadFeed.swift +++ b/Shared/SmartFeeds/UnreadFeed.swift @@ -73,16 +73,11 @@ extension UnreadFeed: ArticleFetcher { func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - fetchUnreadArticlesAsync(completion) + AccountManager.shared.fetchArticlesAsync(fetchType, completion) } func fetchUnreadArticles() async throws -> Set
{ try await AccountManager.shared.fetchArticles(fetchType: fetchType) } - - func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - AccountManager.shared.fetchArticlesAsync(fetchType, completion) - } } diff --git a/Shared/Timeline/FetchRequestOperation.swift b/Shared/Timeline/FetchRequestOperation.swift index 69b118050..06158290a 100644 --- a/Shared/Timeline/FetchRequestOperation.swift +++ b/Shared/Timeline/FetchRequestOperation.swift @@ -62,7 +62,7 @@ final class FetchRequestOperation { var fetchersReturned = 0 var fetchedArticles = Set
() - func process(_ articles: Set
) { + func process(_ articles: Set
?) { precondition(Thread.isMainThread) guard !self.isCanceled else { callCompletionIfNeeded() @@ -71,7 +71,10 @@ final class FetchRequestOperation { assert(!self.isFinished) - fetchedArticles.formUnion(articles) + if let articles { + fetchedArticles.formUnion(articles) + } + fetchersReturned += 1 if fetchersReturned == numberOfFetchers { self.isFinished = true @@ -80,19 +83,16 @@ final class FetchRequestOperation { } } - for fetcher in fetchers { - if (fetcher as? SidebarItem)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true { - fetcher.fetchUnreadArticlesAsync { articleSetResult in - let articles = (try? articleSetResult.get()) ?? Set
() + Task { @MainActor in + for fetcher in fetchers { + if (fetcher as? SidebarItem)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true { + let articles = try? await fetcher.fetchUnreadArticles() process(articles) - } - } else { - fetcher.fetchArticlesAsync { articleSetResult in - let articles = (try? articleSetResult.get()) ?? Set
() + } else { + let articles = try? await fetcher.fetchArticles() process(articles) } } - } } }