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:
@@ -1231,18 +1231,18 @@ private extension Account {
|
||||
return articles
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetResultBlock) {
|
||||
@MainActor func fetchArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetResultBlock) {
|
||||
|
||||
let feeds = container.flattenedFeeds()
|
||||
database.fetchArticlesAsync(feeds.feedIDs()) { [weak self] (articleSetResult) in
|
||||
Task { @MainActor [weak self] in
|
||||
switch articleSetResult {
|
||||
case .success(let articles):
|
||||
self?.validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles)
|
||||
completion(.success(articles))
|
||||
case .failure(let databaseError):
|
||||
completion(.failure(databaseError))
|
||||
}
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
do {
|
||||
let articles = try await self.database.articlesForFeeds(feeds.feedIDs())
|
||||
self.validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles)
|
||||
completion(.success(articles))
|
||||
} catch {
|
||||
completion(.failure(error as! DatabaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,8 +140,8 @@ public typealias ArticleStatusesResultBlock = (ArticleStatusesResult) -> Void
|
||||
try await articlesTable.articlesForFeed(feedID)
|
||||
}
|
||||
|
||||
public func fetchArticlesAsync(_ feedIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
|
||||
articlesTable.fetchArticlesAsync(feedIDs, completion)
|
||||
public func articlesForFeeds(_ feedIDs: Set<String>) async throws -> Set<Article> {
|
||||
try await articlesTable.articlesForFeeds(feedIDs)
|
||||
}
|
||||
|
||||
public func fetchArticlesAsync(articleIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
|
||||
|
||||
@@ -61,6 +61,19 @@ final class ArticlesTable: DatabaseTable {
|
||||
}
|
||||
}
|
||||
|
||||
func articlesForFeeds(_ feedIDs: Set<String>) async throws -> Set<Article> {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
fetchArticlesAsync({ self.fetchArticlesForFeedIDs(feedIDs, $0) }) { articleSetResult in
|
||||
switch articleSetResult {
|
||||
case .success(let articles):
|
||||
continuation.resume(returning: articles)
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fetchArticles(_ feedID: String) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchArticlesForFeedID(feedID, $0) }
|
||||
}
|
||||
@@ -70,11 +83,11 @@ final class ArticlesTable: DatabaseTable {
|
||||
}
|
||||
|
||||
func fetchArticles(_ feedIDs: Set<String>) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchArticles(feedIDs, $0) }
|
||||
return try fetchArticles{ self.fetchArticlesForFeedIDs(feedIDs, $0) }
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(_ feedIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
|
||||
fetchArticlesAsync({ self.fetchArticles(feedIDs, $0) }, completion)
|
||||
fetchArticlesAsync({ self.fetchArticlesForFeedIDs(feedIDs, $0) }, completion)
|
||||
}
|
||||
|
||||
// MARK: - Fetching Articles by articleID
|
||||
@@ -875,7 +888,7 @@ private extension ArticlesTable {
|
||||
return articlesWithResultSet(resultSet, database)
|
||||
}
|
||||
|
||||
func fetchArticles(_ feedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
|
||||
func fetchArticlesForFeedIDs(_ feedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
|
||||
// select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and read=0
|
||||
if feedIDs.isEmpty {
|
||||
return Set<Article>()
|
||||
|
||||
Reference in New Issue
Block a user