From e523e06efe017ec57aa40f63231ee7f803cc17f3 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 4 Apr 2024 17:37:13 -0700 Subject: [PATCH] Convert createStatusesIfNeeded to async await. --- Account/Sources/Account/Account.swift | 16 ++++------------ ...eedlyIngestStreamArticleIdsOperation.swift | 19 +++++++++---------- .../ArticlesDatabaseCompatibility.swift | 14 -------------- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 4245ec84c..481052186 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -880,22 +880,14 @@ public enum FetchType { /// Make sure statuses exist. Any existing statuses won’t be touched. /// All created statuses will be marked as read and not starred. /// Sends a .StatusesDidChange notification. - func createStatusesIfNeeded(articleIDs: Set, completion: DatabaseCompletionBlock? = nil) { + func createStatusesIfNeeded(articleIDs: Set) async throws { + guard !articleIDs.isEmpty else { - completion?(nil) return } - database.createStatusesIfNeeded(articleIDs: articleIDs) { error in - MainActor.assumeIsolated { - if let error = error { - completion?(error) - return - } - self.noteStatusesForArticleIDsDidChange(articleIDs) - completion?(nil) - } - } + try await database.createStatusesIfNeeded(articleIDs: articleIDs) + noteStatusesForArticleIDsDidChange(articleIDs) } /// Mark articleIDs statuses based on statusKey and flag. diff --git a/Account/Sources/Account/Feedly/Operations/FeedlyIngestStreamArticleIdsOperation.swift b/Account/Sources/Account/Feedly/Operations/FeedlyIngestStreamArticleIdsOperation.swift index d35a22920..e24c104b7 100644 --- a/Account/Sources/Account/Feedly/Operations/FeedlyIngestStreamArticleIdsOperation.swift +++ b/Account/Sources/Account/Feedly/Operations/FeedlyIngestStreamArticleIdsOperation.swift @@ -48,26 +48,25 @@ class FeedlyIngestStreamArticleIdsOperation: FeedlyOperation { didFinish() return } - + switch result { - case .success(let streamIds): - account.createStatusesIfNeeded(articleIDs: Set(streamIds.ids)) { databaseError in + case .success(let streamIDs): - MainActor.assumeIsolated { - if let error = databaseError { - self.didFinish(with: error) - return - } + Task { @MainActor in + do { + try await account.createStatusesIfNeeded(articleIDs: Set(streamIDs.ids)) - guard let continuation = streamIds.continuation else { + guard let continuation = streamIDs.continuation else { os_log(.debug, log: self.log, "Reached end of stream for %@", self.resource.id) self.didFinish() return } self.getStreamIds(continuation) + } catch { + self.didFinish(with: error) + return } - } case .failure(let error): didFinish(with: error) diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift index edc3bec63..5b64c7266 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabaseCompatibility.swift @@ -95,20 +95,6 @@ public extension ArticlesDatabase { } } - /// Create statuses for specified articleIDs. For existing statuses, don’t do anything. - /// For newly-created statuses, mark them as read and not-starred. - nonisolated func createStatusesIfNeeded(articleIDs: Set, completion: @escaping DatabaseCompletionBlock) { - - Task { - do { - try await createStatusesIfNeeded(articleIDs: articleIDs) - callDatabaseCompletion(completion) - } catch { - callDatabaseCompletion(completion, .suspended) - } - } - } - nonisolated private func callUpdateArticlesCompletion(_ completion: @escaping UpdateArticlesCompletionBlock, _ result: UpdateArticlesResult) { Task { @MainActor in