diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index 14fceaa03..8c8187e1e 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -494,6 +494,12 @@ public enum FetchType { try ActivityLog.shared.logActivity(owner: activityOwner, kind: kind, detail: detail, successMessage: successMessage, durationIsSignificant: durationIsSignificant, work) } + /// Fetches one page or chunk of a paginated refresh as its own numbered, timed + /// sub-activity of `kind`, reporting the page's item count. + func logRefreshPage(kind: ActivityKind, message: @escaping (T) -> String, _ fetch: () async throws -> T) async throws -> T { + try await logActivity(kind: kind, detail: ActivityLog.shared.nextTaskNumberString(), successMessage: message, fetch) + } + // MARK: - Syncing Article Status public func sendArticleStatus() async throws { diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index a6885b243..7c75e0909 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -347,7 +347,7 @@ import Secrets for (chunkIndex, chunk) in chunks.enumerated() { let chunkIDs = Set(chunk) do { - try await logRefreshPage(for: account, kind: .sendArticleStatuses, message: { _ in "\(chunkIDs.count) \(pairing.action.rawValue)" }, { try await caller.mark(chunkIDs, as: pairing.action) }) + try await account.logRefreshPage(kind: .sendArticleStatuses, message: { _ in "\(chunkIDs.count) \(pairing.action.rawValue)" }, { try await caller.mark(chunkIDs, as: pairing.action) }) await syncDatabase.deleteSelectedForProcessing(chunkIDs, key: pairing.key) sentCount += chunkIDs.count } catch { @@ -944,7 +944,7 @@ private extension FeedlyAccountDelegate { var continuation: String? var pageCount = 0 repeat { - let page = try await self.logRefreshPage(for: account, kind: .fetchArticleIDs, message: { "\($0.ids.count) article IDs" }, { try await self.caller.getStreamIDs(for: resource, continuation: continuation, newerThan: newerThan, unreadOnly: nil) }) + let page = try await account.logRefreshPage(kind: .fetchArticleIDs, message: { "\($0.ids.count) article IDs" }, { try await self.caller.getStreamIDs(for: resource, continuation: continuation, newerThan: newerThan, unreadOnly: nil) }) await account.createStatusesIfNeededAsync(articleIDs: Set(page.ids)) collected.formUnion(page.ids) continuation = page.continuation @@ -1020,7 +1020,7 @@ private extension FeedlyAccountDelegate { var continuation: String? var pageCount = 0 repeat { - let page = try await logRefreshPage(for: account, kind: kind, message: { "\($0.ids.count) article IDs" }, { try await self.caller.getStreamIDs(for: resource, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly) }) + let page = try await account.logRefreshPage(kind: kind, message: { "\($0.ids.count) article IDs" }, { try await self.caller.getStreamIDs(for: resource, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly) }) collected.formUnion(page.ids) continuation = page.continuation pageCount += 1 @@ -1031,12 +1031,6 @@ private extension FeedlyAccountDelegate { return collected } - /// Fetches one page or chunk of a paginated refresh as its own numbered, timed - /// sub-activity of `kind`, reporting the page's item count. - private func logRefreshPage(for account: Account, kind: ActivityKind, message: @escaping (T) -> String, _ fetch: () async throws -> T) async throws -> T { - try await account.logActivity(kind: kind, detail: ActivityLog.shared.nextTaskNumberString(), successMessage: message, fetch) - } - /// Fetch full entries for `articleIDs` and update the account, in 1000-ID chunks, /// in order — the front of the list survives the per-sync cap. /// Returns the count of articles ingested. @@ -1056,7 +1050,7 @@ private extension FeedlyAccountDelegate { Self.logger.info("Feedly: downloading \(Self.maxArticleDownloadChunksPerSync * Self.articleDownloadChunkSize) of \(articleIDs.count) articles this sync — the rest follow on later syncs") } for chunk in chunks.prefix(Self.maxArticleDownloadChunksPerSync) { - let entries = try await self.logRefreshPage(for: account, kind: .refreshMissingArticles, message: { "\($0.count) articles" }, { try await self.caller.getEntries(for: Set(chunk)) }) + let entries = try await account.logRefreshPage(kind: .refreshMissingArticles, message: { "\($0.count) articles" }, { try await self.caller.getEntries(for: Set(chunk)) }) await self.ingest(entries: entries, into: account) ingested += entries.count } @@ -1117,7 +1111,7 @@ private extension FeedlyAccountDelegate { var continuation: String? var pageCount = 0 repeat { - let stream = try await logRefreshPage(for: account, kind: .refreshArticles, message: { "\($0.items.count) articles" }, { try await caller.getStreamContents(for: resource, continuation: continuation, newerThan: newerThan, unreadOnly: nil, count: count) }) + let stream = try await account.logRefreshPage(kind: .refreshArticles, message: { "\($0.items.count) articles" }, { try await caller.getStreamContents(for: resource, continuation: continuation, newerThan: newerThan, unreadOnly: nil, count: count) }) let pageResult = await ingest(entries: stream.items, into: account) result.newArticleCount += pageResult.newArticleCount result.newUnreadArticleIDs.formUnion(pageResult.newUnreadArticleIDs) diff --git a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift index adb8aa7df..5444f3daa 100644 --- a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift +++ b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift @@ -41,12 +41,6 @@ import os } } - /// Fetches one page or chunk of a paginated refresh as its own numbered, timed - /// sub-activity of `kind`, reporting the page's item count. - func logRefreshPage(for account: Account, kind: ActivityKind, message: @escaping (T) -> String, _ fetch: () async throws -> T) async throws -> T { - try await account.logActivity(kind: kind, detail: ActivityLog.shared.nextTaskNumberString(), successMessage: message, fetch) - } - @MainActor func syncFolders(_ account: Account, _ folders: [NewsBlurFolder]?) { guard let folders else { return } assert(Thread.isMainThread) @@ -378,7 +372,7 @@ import os refreshProgress.completeTask() } - let (stories, _) = try await logRefreshPage(for: account, kind: .refreshArticles, message: { "\($0.0?.count ?? 0) articles" }, { try await caller.retrieveStories(feedID: feed.feedID, page: page) }) + let (stories, _) = try await account.logRefreshPage(kind: .refreshArticles, message: { "\($0.0?.count ?? 0) articles" }, { try await caller.retrieveStories(feedID: feed.feedID, page: page) }) guard let stories, stories.count > 0 else { return } diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index f6a2c7803..10cfedb74 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -243,7 +243,7 @@ import Secrets for chunk in chunkedStoryHashes { do { - let (stories, _) = try await logRefreshPage(for: account, kind: .refreshMissingArticles, message: { "\($0.0?.count ?? 0) articles" }, { try await caller.retrieveStories(hashes: chunk) }) + let (stories, _) = try await account.logRefreshPage(kind: .refreshMissingArticles, message: { "\($0.0?.count ?? 0) articles" }, { try await caller.retrieveStories(hashes: chunk) }) await processStories(account: account, stories: stories) } catch { savedError = error diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 51001d3f5..0d7149408 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -766,12 +766,6 @@ private extension ReaderAPIAccountDelegate { } } - /// Fetches one page or chunk of a paginated refresh as its own numbered, timed - /// sub-activity of `kind`, reporting the page's item count. - func logRefreshPage(for account: Account, kind: ActivityKind, message: @escaping (T) -> String, _ fetch: () async throws -> T) async throws -> T { - try await account.logActivity(kind: kind, detail: ActivityLog.shared.nextTaskNumberString(), successMessage: message, fetch) - } - /// Returns a per-page handler for paginated `retrieveItemIDs` calls, logging each /// page as a numbered sub-activity of `kind` reporting the page's article-ID count. func articleIDPageHandler(for account: Account, kind: ActivityKind) -> @MainActor (Int) -> Void { @@ -978,7 +972,7 @@ private extension ReaderAPIAccountDelegate { for articleIDGroup in articleIDGroups { do { - try await logRefreshPage(for: account, kind: .sendArticleStatuses, message: { _ in "\(articleIDGroup.count) \(label)" }, { try await apiCall(articleIDGroup) }) + try await account.logRefreshPage(kind: .sendArticleStatuses, message: { _ in "\(articleIDGroup.count) \(label)" }, { try await apiCall(articleIDGroup) }) await syncDatabase.deleteSelectedForProcessing(Set(articleIDGroup), key: key) sentCount += articleIDGroup.count } catch { @@ -1095,7 +1089,7 @@ private extension ReaderAPIAccountDelegate { for chunk in chunkedArticleIDs { do { - let entries = try await logRefreshPage(for: account, kind: .refreshMissingArticles, message: { "\($0?.count ?? 0) articles" }, { try await caller.retrieveEntries(articleIDs: chunk) }) + let entries = try await account.logRefreshPage(kind: .refreshMissingArticles, message: { "\($0?.count ?? 0) articles" }, { try await caller.retrieveEntries(articleIDs: chunk) }) refreshProgress.completeTask() await processEntries(account: account, entries: entries) } catch {