diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift index bd3120989..e6449bcf8 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift @@ -14,9 +14,6 @@ import Articles // This file exists for compatibility — it provides nonisolated functions and callback-based APIs. // It will go away as we adopt structured concurrency. -public typealias UnreadCountDictionaryCompletionResult = Result -public typealias UnreadCountDictionaryCompletionBlock = @Sendable (UnreadCountDictionaryCompletionResult) -> Void - public typealias SingleUnreadCountResult = Result public typealias SingleUnreadCountCompletionBlock = @Sendable (SingleUnreadCountResult) -> Void @@ -34,169 +31,8 @@ public typealias ArticleStatusesResultBlock = (ArticleStatusesResult) -> Void public extension ArticlesDatabase { - // MARK: - Fetching Articles Async - - nonisolated func fetchArticlesAsync(_ feedID: String, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await articles(feedID: feedID) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchArticlesAsync(_ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await articles(feedIDs: feedIDs) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchArticlesAsync(articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await articles(articleIDs: articleIDs) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchUnreadArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await unreadArticles(feedIDs: feedIDs, limit: limit) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchTodayArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await todayArticles(feedIDs: feedIDs, limit: limit) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchedStarredArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await starredArticles(feedIDs: feedIDs, limit: limit) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchArticlesMatchingAsync(_ searchString: String, _ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await articlesMatching(searchString: searchString, feedIDs: feedIDs) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - - Task { - do { - let articles = try await articlesMatching(searchString: searchString, articleIDs: articleIDs) - callArticleSetCompletion(completion, .success(articles)) - } catch { - callArticleSetCompletion(completion, .failure(.suspended)) - } - } - } - // MARK: - Unread Counts - /// Fetch all non-zero unread counts. - nonisolated func fetchAllUnreadCounts(_ completion: @escaping UnreadCountDictionaryCompletionBlock) { - - Task { - do { - let unreadCountDictionary = try await allUnreadCounts() - callUnreadCountDictionaryCompletion(completion, .success(unreadCountDictionary)) - } catch { - callUnreadCountDictionaryCompletion(completion, .failure(.suspended)) - } - } - } - - /// Fetch unread count for a single feed. - nonisolated func fetchUnreadCount(_ feedID: String, _ completion: @escaping SingleUnreadCountCompletionBlock) { - - Task { - do { - let unreadCount = try await unreadCount(feedID: feedID) ?? 0 - callSingleUnreadCountCompletion(completion, .success(unreadCount)) - } catch { - callSingleUnreadCountCompletion(completion, .failure(.suspended)) - } - } - } - - /// Fetch non-zero unread counts for given feedIDs. - nonisolated func fetchUnreadCounts(for feedIDs: Set, _ completion: @escaping UnreadCountDictionaryCompletionBlock) { - - Task { - do { - let unreadCountDictionary = try await unreadCounts(feedIDs: feedIDs) - callUnreadCountDictionaryCompletion(completion, .success(unreadCountDictionary)) - } catch { - callUnreadCountDictionaryCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchUnreadCountForToday(for feedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { - - Task { - do { - let unreadCount = try await unreadCountForToday(feedIDs: feedIDs)! - callSingleUnreadCountCompletion(completion, .success(unreadCount)) - } catch { - callSingleUnreadCountCompletion(completion, .failure(.suspended)) - } - } - } - - nonisolated func fetchUnreadCount(for feedIDs: Set, since: Date, completion: @escaping SingleUnreadCountCompletionBlock) { - - Task { - do { - let unreadCount = try await unreadCount(feedIDs: feedIDs, since: since)! - callSingleUnreadCountCompletion(completion, .success(unreadCount)) - } catch { - callSingleUnreadCountCompletion(completion, .failure(.suspended)) - } - } - } - nonisolated func fetchStarredAndUnreadCount(for feedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { Task { @@ -329,13 +165,6 @@ public extension ArticlesDatabase { } } - nonisolated private func callUnreadCountDictionaryCompletion(_ completion: @escaping UnreadCountDictionaryCompletionBlock, _ result: UnreadCountDictionaryCompletionResult) { - - Task { @MainActor in - completion(result) - } - } - nonisolated private func callSingleUnreadCountCompletion(_ completion: @escaping SingleUnreadCountCompletionBlock, _ result: SingleUnreadCountResult) { Task { @MainActor in @@ -350,13 +179,6 @@ public extension ArticlesDatabase { } } - nonisolated private func callArticleSetCompletion(_ completion: @escaping ArticleSetResultBlock, _ result: ArticleSetResult) { - - Task { @MainActor in - completion(result) - } - } - nonisolated private func callArticleStatusesCompletion(_ completion: @escaping ArticleStatusesResultBlock, _ result: ArticleStatusesResult) { Task { @MainActor in