diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 2dafb4852..9e68a4855 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -1221,7 +1221,21 @@ private extension Account { } func fetchArticlesMatchingAsync(_ searchString: String, _ completion: @escaping ArticleSetResultBlock) { - database.fetchArticlesMatchingAsync(searchString, flattenedFeeds().feedIDs(), completion) + Task { @MainActor in + + let feedIDs = flattenedFeeds().feedIDs() + + do { + let articles = try await database.articlesForSearchStringInFeeds(searchString, feedIDs) + Task { @MainActor in + completion(.success(articles)) + } + } catch { + Task { @MainActor in + completion(.failure(error as! DatabaseError)) + } + } + } } func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift index 3f6fd784b..8169f9f13 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift @@ -160,8 +160,8 @@ public typealias ArticleStatusesResultBlock = (ArticleStatusesResult) -> Void try await articlesTable.starredArticlesForFeedIDs(feedIDs, limit) } - public func fetchArticlesMatchingAsync(_ searchString: String, _ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchArticlesMatchingAsync(searchString, feedIDs, completion) + public func articlesForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set) async throws -> Set
{ + try await articlesTable.articleForSearchStringInFeeds(searchString, feedIDs) } public func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift index 7b601d6af..1e8051ebe 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift @@ -149,8 +149,8 @@ final class ArticlesTable: DatabaseTable { return articles } - func fetchArticlesMatchingAsync(_ searchString: String, _ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesMatching(searchString, feedIDs, $0) }, completion) + func articleForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set) async throws -> Set
{ + try await articlesWithFetchMethod { self.fetchArticlesMatching(searchString, feedIDs, $0) } } func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) {