Remove numerous fetchArticlesAsync methods.

This commit is contained in:
Brent Simmons 2024-03-24 23:06:30 -07:00
parent aab7ab7a80
commit f6e8d3afb1
7 changed files with 3 additions and 101 deletions

View File

@ -718,10 +718,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
}
public func articles(feed: Feed) async throws -> Set<Article> {
@MainActor public func articles(feed: Feed) async throws -> Set<Article> {
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<Article> {
@MainActor public func unreadArticles(feed: Feed) async throws -> Set<Article> {
try await database.unreadArticles(feedIDs: Set([feed.feedID]))
}

View File

@ -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<Article>()))
return
}
var allFetchedArticles = Set<Article>()
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.

View File

@ -13,8 +13,6 @@ import ArticlesDatabase
public protocol ArticleFetcher {
@MainActor func fetchArticles() async throws -> Set<Article>
@MainActor func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock)
@MainActor func fetchUnreadArticles() async throws -> Set<Article>
}
@ -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<Article>()))
return
}
account.fetchArticlesAsync(.feed(self), completion)
}
public func fetchUnreadArticles() async throws -> Set<Article> {
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<Article>()))
return
}
account.fetchArticlesAsync(.folder(self, false), completion)
}
public func fetchUnreadArticles() async throws -> Set<Article> {
try await articles(unreadOnly: true)

View File

@ -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)
}
// Doesnt actually fetch unread articles. Fetches whatever articleID it is asked to fetch.
public func fetchUnreadArticles() async throws -> Set<Article> {
try await fetchArticles()
}
public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
return account.fetchArticlesAsync(.articleIDs(Set([articleID])), completion)
}
}

View File

@ -94,11 +94,6 @@ extension SmartFeed: ArticleFetcher {
try await delegate.fetchArticles()
}
func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
delegate.fetchArticlesAsync(completion)
}
func fetchUnreadArticles() async throws -> Set<Article> {
try await delegate.fetchUnreadArticles()

View File

@ -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<Article> {
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))
}
}
}
}

View File

@ -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<Article> {
try await AccountManager.shared.fetchArticles(fetchType: fetchType)