From 373d7ed98b60f60c443dd9d1f6324ebe05facc97 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 1 Oct 2023 14:15:17 -0700 Subject: [PATCH] Continue converting ArticlesDatabase to async/await. --- Account/Sources/Account/Account.swift | 14 +++++++++++++- .../ArticlesDatabase/ArticlesDatabase.swift | 8 ++++---- .../Sources/ArticlesDatabase/ArticlesTable.swift | 6 +++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 9e68a4855..5585cdd9d 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -1239,7 +1239,19 @@ private extension Account { } func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - database.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion) + + Task { @MainActor in + do { + let articles = try await database.articlesForSearchStringInArticleIDs(searchString, articleIDs) + Task { @MainActor in + completion(.success(articles)) + } + } catch { + Task { @MainActor in + completion(.failure(error as! DatabaseError)) + } + } + } } func fetchArticles(articleIDs: Set) throws -> Set
{ diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift index 8169f9f13..2ae827e29 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift @@ -161,13 +161,13 @@ public typealias ArticleStatusesResultBlock = (ArticleStatusesResult) -> Void } public func articlesForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set) async throws -> Set
{ - try await articlesTable.articleForSearchStringInFeeds(searchString, feedIDs) + try await articlesTable.articlesForSearchStringInFeeds(searchString, feedIDs) } - public func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion) + public func articlesForSearchStringInArticleIDs(_ searchString: String, _ articleIDs: Set) async throws -> Set
{ + try await articlesTable.articlesForSearchStringInArticleIDs(searchString, articleIDs) } - + // MARK: - Unread Counts /// Fetch all non-zero unread counts. diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift index 1e8051ebe..0ab97ec35 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift @@ -149,12 +149,12 @@ final class ArticlesTable: DatabaseTable { return articles } - func articleForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set) async throws -> Set
{ + func articlesForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set) async throws -> Set
{ try await articlesWithFetchMethod { self.fetchArticlesMatching(searchString, feedIDs, $0) } } - func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs, $0) }, completion) + func articlesForSearchStringInArticleIDs(_ searchString: String, _ articleIDs: Set) async throws -> Set
{ + try await articlesWithFetchMethod { self.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs, $0) } } // MARK: - Fetching Articles for Indexer