mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Continue converting ArticlesDatabase to async/await.
This commit is contained in:
@@ -1152,7 +1152,16 @@ private extension Account {
|
||||
}
|
||||
|
||||
func fetchTodayArticlesAsync(limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
database.fetchTodayArticlesAsync(flattenedFeeds().feedIDs(), limit, completion)
|
||||
Task { @MainActor in
|
||||
let feedIDs = flattenedFeeds().feedIDs()
|
||||
|
||||
do {
|
||||
let articles = try await database.todayArticlesForFeeds(feedIDs, limit)
|
||||
completion(.success(articles))
|
||||
} catch {
|
||||
completion(.failure(error as! DatabaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor func fetchArticles(folder: Folder) throws -> Set<Article> {
|
||||
@@ -1225,7 +1234,7 @@ private extension Account {
|
||||
Task { @MainActor in
|
||||
completion(.failure(error as! DatabaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1277,25 +1286,26 @@ private extension Account {
|
||||
}
|
||||
|
||||
func fetchUnreadArticlesAsync(forContainer container: Container, limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
let feeds = container.flattenedFeeds()
|
||||
database.fetchUnreadArticlesAsync(feeds.feedIDs(), limit) { [weak self] (articleSetResult) in
|
||||
Task { @MainActor [weak self] in
|
||||
switch articleSetResult {
|
||||
case .success(let articles):
|
||||
Task { @MainActor in
|
||||
|
||||
let feeds = container.flattenedFeeds()
|
||||
let feedIDs = feeds.feedIDs()
|
||||
|
||||
// We don't validate limit queries because they, by definition, won't correctly match the
|
||||
// complete unread state for the given container.
|
||||
if limit == nil {
|
||||
self?.validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles)
|
||||
}
|
||||
do {
|
||||
let articles = try await database.unreadArticlesForFeeds(feedIDs, limit)
|
||||
|
||||
completion(.success(articles))
|
||||
case .failure(let databaseError):
|
||||
completion(.failure(databaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// We don't validate limit queries because they, by definition, won't correctly match the
|
||||
// complete unread state for the given container.
|
||||
if limit == nil {
|
||||
self.validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles)
|
||||
}
|
||||
|
||||
completion(.success(articles))
|
||||
} catch {
|
||||
completion(.failure(error as! DatabaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor func validateUnreadCountsAfterFetchingUnreadArticles(_ feeds: Set<Feed>, _ articles: Set<Article>) {
|
||||
// Validate unread counts. This was the site of a performance slowdown:
|
||||
|
||||
@@ -148,12 +148,12 @@ public typealias ArticleStatusesResultBlock = (ArticleStatusesResult) -> Void
|
||||
try await articlesTable.articlesForArticleIDs(articleIDs)
|
||||
}
|
||||
|
||||
public func fetchUnreadArticlesAsync(_ feedIDs: Set<String>, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
articlesTable.fetchUnreadArticlesAsync(feedIDs, limit, completion)
|
||||
public func unreadArticlesForFeeds(_ feedIDs: Set<String>, _ limit: Int?) async throws -> Set<Article> {
|
||||
try await articlesTable.unreadArticlesForFeeds(feedIDs, limit)
|
||||
}
|
||||
|
||||
public func fetchTodayArticlesAsync(_ feedIDs: Set<String>, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
articlesTable.fetchArticlesSinceAsync(feedIDs, todayCutoffDate(), limit, completion)
|
||||
public func todayArticlesForFeeds(_ feedIDs: Set<String>, _ limit: Int?) async throws -> Set<Article> {
|
||||
try await articlesTable.articlesForFeedIDsSince(feedIDs, todayCutoffDate(), limit)
|
||||
}
|
||||
|
||||
public func fetchedStarredArticlesAsync(_ feedIDs: Set<String>, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
|
||||
@@ -88,8 +88,8 @@ final class ArticlesTable: DatabaseTable {
|
||||
return try fetchArticles{ self.fetchUnreadArticlesBetween(feedIDs, limit, $0, before, after) }
|
||||
}
|
||||
|
||||
func fetchUnreadArticlesAsync(_ feedIDs: Set<String>, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
fetchArticlesAsync({ self.fetchUnreadArticles(feedIDs, limit, $0) }, completion)
|
||||
func unreadArticlesForFeeds(_ feedIDs: Set<String>, _ limit: Int?) async throws -> Set<Article> {
|
||||
try await articlesWithFetchMethod { self.fetchUnreadArticles(feedIDs, limit, $0) }
|
||||
}
|
||||
|
||||
// MARK: - Fetching Today Articles
|
||||
@@ -98,8 +98,8 @@ final class ArticlesTable: DatabaseTable {
|
||||
return try fetchArticles{ self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) }
|
||||
}
|
||||
|
||||
func fetchArticlesSinceAsync(_ feedIDs: Set<String>, _ cutoffDate: Date, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
fetchArticlesAsync({ self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) }, completion)
|
||||
func articlesForFeedIDsSince(_ feedIDs: Set<String>, _ cutoffDate: Date, _ limit: Int?) async throws -> Set<Article> {
|
||||
try await articlesWithFetchMethod { self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) }
|
||||
}
|
||||
|
||||
// MARK: - Fetching Starred Articles
|
||||
|
||||
Reference in New Issue
Block a user