mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 16:26:04 +00:00
Replace the three copied logRefreshPage implementations with one shared Account method.
This commit is contained in:
1 parent
468e17456b
commit
696fcd3da5
5 files changed
+15
-27
No files matched your search
@@ -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<T>(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 {
|
||||
|
||||
@@ -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<T>(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)
|
||||
|
||||
+1
-7
@@ -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<T>(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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<T>(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 {
|
||||
|
||||
Reference in new issue
Block a user