diff --git a/Mac/Activity/ActivityLogWindowController.swift b/Mac/Activity/ActivityLogWindowController.swift index b83f6db02..4f432e6fb 100644 --- a/Mac/Activity/ActivityLogWindowController.swift +++ b/Mac/Activity/ActivityLogWindowController.swift @@ -520,7 +520,9 @@ private extension ActivityLogWindowController { case .markArticles: return "Marking articles" case .cleanUpCloudKitRecords: - return "Weekly record cleanup" + return "Cleaning up iCloud records" + case .fetchCloudKitStats: + return "Fetching iCloud stats" case .uploadNewArticles: return "Uploading new articles" case .subscribeToCloudKitZone: diff --git a/Mac/Activity/ActivityWindowController.swift b/Mac/Activity/ActivityWindowController.swift index 4cba2f314..a97ea6565 100644 --- a/Mac/Activity/ActivityWindowController.swift +++ b/Mac/Activity/ActivityWindowController.swift @@ -488,7 +488,9 @@ private extension ActivityWindowController { case .markArticles: return NSLocalizedString("Marking articles", comment: "Activity kind") case .cleanUpCloudKitRecords: - return NSLocalizedString("Weekly record cleanup", comment: "Activity kind") + return NSLocalizedString("Cleaning up iCloud records", comment: "Activity kind") + case .fetchCloudKitStats: + return NSLocalizedString("Fetching iCloud stats", comment: "Activity kind") case .uploadNewArticles: return NSLocalizedString("Uploading new articles", comment: "Activity kind") case .subscribeToCloudKitZone: diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index ab7e35a5a..cfe65439b 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -586,7 +586,9 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { throw CloudKitAccountDelegateError.unknown } do { - return try await articlesZone.fetchStats(account: account, progress: progress) + return try await account.logActivity(kind: .fetchCloudKitStats) { + try await articlesZone.fetchStats(account: account, progress: progress) + } } catch { Self.logger.error("CloudKitAccountDelegate: fetchCloudKitStats error: \(error)") postSyncError(error, account: account, operation: "Fetching iCloud stats") @@ -599,8 +601,11 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { throw CloudKitAccountDelegateError.unknown } let syncUnreadContent = AccountManager.shared.syncArticleContentForUnreadArticles + let detail = dryRun ? "Dry run" : "Manual" do { - try await articlesZone.cleanUpRecordsUsingCache(account: account, syncUnreadContent: syncUnreadContent, dryRun: dryRun, deleteStaleRecords: false, progress: progress) + try await account.logActivity(kind: .cleanUpCloudKitRecords, detail: detail) { + try await articlesZone.cleanUpRecordsUsingCache(account: account, syncUnreadContent: syncUnreadContent, dryRun: dryRun, deleteStaleRecords: false, progress: progress) + } } catch { Self.logger.error("CloudKitAccountDelegate: cleanUpCloudKit error: \(error)") postSyncError(error, account: account, operation: "Cleaning up iCloud records") @@ -1048,7 +1053,7 @@ private extension CloudKitAccountDelegate { let successMessage: (Int) -> String? = { count in count == 0 ? "no records deleted" : "deleted \(count) record\(count == 1 ? "" : "s")" } - let deleted = try await account.logActivity(kind: .cleanUpCloudKitRecords, successMessage: successMessage) { () -> Int in + let deleted = try await account.logActivity(kind: .cleanUpCloudKitRecords, detail: "Weekly", successMessage: successMessage) { () -> Int in try await articlesZone.cleanUpRecords(account: account, syncUnreadContent: syncUnreadContent, dryRun: false, deleteStaleRecords: false) } Self.logger.info("CloudKitAccountDelegate: weekly cleanup deleted \(deleted, privacy: .public) records") diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index 8864f24f3..3538057ce 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -476,7 +476,9 @@ import Secrets func accountWillBeDeleted(_ account: Account) { Task { @MainActor in - try await caller.logout() + try? await account.logActivity(kind: .validateCredentials, detail: "Logging out of NewsBlur") { + try await caller.logout() + } } } diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 35b7587fc..706709e24 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -838,19 +838,21 @@ private extension ReaderAPIAccountDelegate { refreshProgress.addTasks(5) - // Download the initial articles - let articleIDs = try await caller.retrieveItemIDs(type: .allForFeed, feedID: feed.feedID) + try await account.logActivity(kind: .refreshFeedContent(feedURL: feed.url), detail: feed.nameForDisplay) { + // Download the initial articles + let articleIDs = try await caller.retrieveItemIDs(type: .allForFeed, feedID: feed.feedID) - refreshProgress.completeTask() + refreshProgress.completeTask() - _ = try? await account.markAsReadAsync(articleIDs: Set(articleIDs)) - refreshProgress.completeTask() + _ = try? await account.markAsReadAsync(articleIDs: Set(articleIDs)) + refreshProgress.completeTask() - try? await refreshArticleStatus(for: account) - refreshProgress.completeTask() + try? await refreshArticleStatus(for: account) + refreshProgress.completeTask() - await refreshMissingArticles(account) - refreshProgress.reset() + await refreshMissingArticles(account) + refreshProgress.reset() + } return feed } diff --git a/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift b/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift index 6cd7f1581..f3be20640 100644 --- a/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift +++ b/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift @@ -36,6 +36,7 @@ public enum ActivityKind: Sendable, Hashable { case cleanUpCloudKitRecords case uploadNewArticles case subscribeToCloudKitZone + case fetchCloudKitStats // Maintenance and lifecycle