diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 9649defd2..9ff2cb19e 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -718,10 +718,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } - public func articles(feed: Feed) async throws -> Set
{ + @MainActor public func articles(feed: Feed) async throws -> Set
{ let articles = try await database.articles(feedID: feed.feedID) - await validateUnreadCount(feed, articles) + validateUnreadCount(feed, articles) return articles } @@ -730,7 +730,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, try await database.articles(articleIDs: articleIDs) } - public func unreadArticles(feed: Feed) async throws -> Set
{ + @MainActor public func unreadArticles(feed: Feed) async throws -> Set
{ try await database.unreadArticles(feedIDs: Set([feed.feedID])) } diff --git a/Account/Sources/Account/AccountManager.swift b/Account/Sources/Account/AccountManager.swift index d48ea43b0..1d5c76135 100644 --- a/Account/Sources/Account/AccountManager.swift +++ b/Account/Sources/Account/AccountManager.swift @@ -350,46 +350,6 @@ public final class AccountManager: UnreadCountProvider { return allFetchedArticles } - public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetResultBlock) { - precondition(Thread.isMainThread) - - guard activeAccounts.count > 0 else { - completion(.success(Set
())) - return - } - - var allFetchedArticles = Set
() - var databaseError: DatabaseError? - let dispatchGroup = DispatchGroup() - - for account in activeAccounts { - - dispatchGroup.enter() - - account.fetchArticlesAsync(fetchType) { (articleSetResult) in - precondition(Thread.isMainThread) - - switch articleSetResult { - case .success(let articles): - allFetchedArticles.formUnion(articles) - case .failure(let error): - databaseError = error - } - - dispatchGroup.leave() - } - } - - dispatchGroup.notify(queue: .main) { - if let databaseError { - completion(.failure(databaseError)) - } - else { - completion(.success(allFetchedArticles)) - } - } - } - // MARK: - Caches /// Empty caches that can reasonably be emptied — when the app moves to the background, for instance. diff --git a/Account/Sources/Account/ArticleFetcher.swift b/Account/Sources/Account/ArticleFetcher.swift index 236693f9b..e143fa8ed 100644 --- a/Account/Sources/Account/ArticleFetcher.swift +++ b/Account/Sources/Account/ArticleFetcher.swift @@ -13,8 +13,6 @@ import ArticlesDatabase public protocol ArticleFetcher { @MainActor func fetchArticles() async throws -> Set
- @MainActor func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) - @MainActor func fetchUnreadArticles() async throws -> Set
} @@ -30,15 +28,6 @@ extension Feed: ArticleFetcher { return try await account.articles(feed: self) } - public func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - guard let account = account else { - assertionFailure("Expected feed.account, but got nil.") - completion(.success(Set
())) - return - } - account.fetchArticlesAsync(.feed(self), completion) - } - public func fetchUnreadArticles() async throws -> Set
{ guard let account else { @@ -57,17 +46,6 @@ extension Folder: ArticleFetcher { try await articles(unreadOnly: false) } - public func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - guard let account else { - assertionFailure("Expected folder.account, but got nil.") - completion(.success(Set
())) - return - } - - account.fetchArticlesAsync(.folder(self, false), completion) - } - public func fetchUnreadArticles() async throws -> Set
{ try await articles(unreadOnly: true) diff --git a/Account/Sources/Account/SingleArticleFetcher.swift b/Account/Sources/Account/SingleArticleFetcher.swift index dbc552b50..2f1969154 100644 --- a/Account/Sources/Account/SingleArticleFetcher.swift +++ b/Account/Sources/Account/SingleArticleFetcher.swift @@ -28,20 +28,10 @@ extension SingleArticleFetcher: ArticleFetcher { try await account.articles(articleIDs: Set([articleID])) } - public func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - return account.fetchArticlesAsync(.articleIDs(Set([articleID])), completion) - } - // Doesn’t actually fetch unread articles. Fetches whatever articleID it is asked to fetch. public func fetchUnreadArticles() async throws -> Set
{ try await fetchArticles() } - - public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - return account.fetchArticlesAsync(.articleIDs(Set([articleID])), completion) - } } diff --git a/Shared/SmartFeeds/SmartFeed.swift b/Shared/SmartFeeds/SmartFeed.swift index 64bfcd760..78c5f282e 100644 --- a/Shared/SmartFeeds/SmartFeed.swift +++ b/Shared/SmartFeeds/SmartFeed.swift @@ -94,11 +94,6 @@ extension SmartFeed: ArticleFetcher { try await delegate.fetchArticles() } - func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - delegate.fetchArticlesAsync(completion) - } - func fetchUnreadArticles() async throws -> Set
{ try await delegate.fetchUnreadArticles() diff --git a/Shared/SmartFeeds/SmartFeedDelegate.swift b/Shared/SmartFeeds/SmartFeedDelegate.swift index a039b4856..8ee36d7a7 100644 --- a/Shared/SmartFeeds/SmartFeedDelegate.swift +++ b/Shared/SmartFeeds/SmartFeedDelegate.swift @@ -28,24 +28,8 @@ extension SmartFeedDelegate { try await AccountManager.shared.fetchArticles(fetchType: fetchType) } - @MainActor func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - AccountManager.shared.fetchArticlesAsync(fetchType, completion) - } - @MainActor func fetchUnreadArticles() async throws -> Set
{ try await AccountManager.shared.fetchArticles(fetchType: fetchType) } - - @MainActor func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - fetchArticlesAsync{ articleSetResult in - switch articleSetResult { - case .success(let articles): - completion(.success(articles.unreadArticles())) - case .failure(let error): - completion(.failure(error)) - } - } - } } diff --git a/Shared/SmartFeeds/UnreadFeed.swift b/Shared/SmartFeeds/UnreadFeed.swift index bd13f3a25..eaecec21b 100644 --- a/Shared/SmartFeeds/UnreadFeed.swift +++ b/Shared/SmartFeeds/UnreadFeed.swift @@ -71,11 +71,6 @@ extension UnreadFeed: ArticleFetcher { try await fetchUnreadArticles() } - func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { - - AccountManager.shared.fetchArticlesAsync(fetchType, completion) - } - func fetchUnreadArticles() async throws -> Set
{ try await AccountManager.shared.fetchArticles(fetchType: fetchType)