From 738dac6a49d5e4f69695169d093adeae20c52e5c Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 30 Nov 2024 20:04:56 -0800 Subject: [PATCH] =?UTF-8?q?Restore=20the=20infrastructure=20for=20saving?= =?UTF-8?q?=20conditional=20GET=20info,=20since=20the=20built-in=20caching?= =?UTF-8?q?=20isn=E2=80=99t=20handling=20this=20as=20well=20as=20it=20appe?= =?UTF-8?q?ared=20at=20first.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Account/Sources/Account/Account.swift | 8 ++++++++ .../CloudKit/CloudKitAccountDelegate.swift | 1 + .../CloudKit/CloudKitAccountZoneDelegate.swift | 5 +++-- Account/Sources/Account/DataExtensions.swift | 1 + Account/Sources/Account/WebFeed.swift | 16 ++++++++++++++++ Account/Sources/Account/WebFeedMetadata.swift | 9 +++++++++ Mac/AppDelegate.swift | 8 ++++++++ 7 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 4b70bf4dd..76a6a9206 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -919,6 +919,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, // MARK: - Debug + public func debugDropConditionalGetInfo() { +#if DEBUG + for feed in flattenedWebFeeds() { + feed.dropConditionalGetInfo() + } +#endif + } + public func debugRunSearch() { #if DEBUG let t1 = Date() diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 241522adc..dd752c721 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -792,6 +792,7 @@ private extension CloudKitAccountDelegate { return } self.articlesZone.deleteArticles(webFeedExternalID) { result in + feed.dropConditionalGetInfo() self.syncProgress.completeTask() completion(result) } diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift index fe9a0ca09..d03b917be 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift @@ -82,8 +82,9 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { func removeWebFeed(_ externalID: String) { if let webFeed = account?.existingWebFeed(withExternalID: externalID), let containers = account?.existingContainers(withWebFeed: webFeed) { - containers.forEach { - $0.removeWebFeed(webFeed) + for container in containers { + webFeed.dropConditionalGetInfo() + container.removeWebFeed(webFeed) } } } diff --git a/Account/Sources/Account/DataExtensions.swift b/Account/Sources/Account/DataExtensions.swift index 12349740d..61ddc93cd 100644 --- a/Account/Sources/Account/DataExtensions.swift +++ b/Account/Sources/Account/DataExtensions.swift @@ -26,6 +26,7 @@ public extension WebFeed { public static let editedName = "editedName" public static let authors = "authors" public static let contentHash = "contentHash" + public static let conditionalGetInfo = "conditionalGetInfo" } } diff --git a/Account/Sources/Account/WebFeed.swift b/Account/Sources/Account/WebFeed.swift index b19737e9e..a6db55552 100644 --- a/Account/Sources/Account/WebFeed.swift +++ b/Account/Sources/Account/WebFeed.swift @@ -123,6 +123,15 @@ public final class WebFeed: Feed, Renamable, Hashable { } } + public var conditionalGetInfo: HTTPConditionalGetInfo? { + get { + return metadata.conditionalGetInfo + } + set { + metadata.conditionalGetInfo = newValue + } + } + public var contentHash: String? { get { return metadata.contentHash @@ -235,6 +244,13 @@ public final class WebFeed: Feed, Renamable, Hashable { self.metadata = metadata } + // MARK: - API + + public func dropConditionalGetInfo() { + conditionalGetInfo = nil + contentHash = nil + } + // MARK: - Hashable public func hash(into hasher: inout Hasher) { diff --git a/Account/Sources/Account/WebFeedMetadata.swift b/Account/Sources/Account/WebFeedMetadata.swift index 4c7b29bb9..924472089 100644 --- a/Account/Sources/Account/WebFeedMetadata.swift +++ b/Account/Sources/Account/WebFeedMetadata.swift @@ -26,6 +26,7 @@ final class WebFeedMetadata: Codable { case contentHash case isNotifyAboutNewArticles case isArticleExtractorAlwaysOn + case conditionalGetInfo case externalID = "subscriptionID" case folderRelationship } @@ -102,6 +103,14 @@ final class WebFeedMetadata: Codable { } } + var conditionalGetInfo: HTTPConditionalGetInfo? { + didSet { + if conditionalGetInfo != oldValue { + valueDidChange(.conditionalGetInfo) + } + } + } + var externalID: String? { didSet { if externalID != oldValue { diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 4b05e161d..5baa8a438 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -704,6 +704,14 @@ extension AppDelegate { AccountManager.shared.defaultAccount.debugRunSearch() } + @IBAction func debugDropConditionalGetInfo(_ sender: Any?) { +#if DEBUG + for account in AccountManager.shared.activeAccounts { + account.debugDropConditionalGetInfo() + } +#endif + } + @IBAction func debugTestCrashReporterWindow(_ sender: Any?) { #if DEBUG crashReportWindowController = CrashReportWindowController(crashLogText: "This is a test crash log.")