From c6c457e71864bda53db346e417d1f28fceba682a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 28 Apr 2024 21:12:39 -0700 Subject: [PATCH] Create fetchAndProcessAllArticleIDs function to replace FeedlyIngestStreamArticleIDsOperation. --- .../FeedlyAccountDelegate.swift | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift b/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift index e5319fd73..0c21f8898 100644 --- a/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate.swift @@ -902,11 +902,44 @@ final class FeedlyAccountDelegate: AccountDelegate { func fetchAndProcessStarredArticleIDs() async throws { // To replace FeedlyIngestStarredArticleIDsOperation - + let remoteArticleIDs = try await fetchRemoteStarredArticleIDs() try await processStarredArticleIDs(remoteArticleIDs: remoteArticleIDs) } + func fetchAllArticleIDs() async throws -> Set { + + guard let userID else { return Set() } + + var allArticleIDs = Set() + let resource = FeedlyCategoryResourceID.Global.all(for: userID) + + func fetchStreamIDs(_ continuation: String?) async throws { + + let streamIDs = try await caller.getStreamIDs(for: resource, continuation: continuation, newerThan: nil, unreadOnly: nil) + + allArticleIDs.formUnion(streamIDs.ids) + + guard let continuation = streamIDs.continuation else { + os_log(.debug, log: self.log, "Reached end of stream for %@", resource.id) + return + } + + try await fetchStreamIDs(continuation) + } + + return allArticleIDs + } + + func fetchAndProcessAllArticleIDs() async throws { + + // To replace FeedlyIngestStreamArticleIDsOperation + + guard let account else { return } + + let allArticleIDs = try await fetchAllArticleIDs() + try await account.createStatusesIfNeeded(articleIDs: allArticleIDs) + } // MARK: Suspend and Resume (for iOS) @@ -918,7 +951,7 @@ final class FeedlyAccountDelegate: AccountDelegate { } } - /// Suspend the SQLLite databases + /// Suspend the SQLite databases func suspendDatabase() { Task { await syncDatabase.suspend()