diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index 8b00ebc0f..e51739957 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -673,6 +673,13 @@ public enum FetchType { return feed } + func clearFeedSettings(_ feed: Feed) { + // Call before permanently removing a feed so the next feed created at this URL + // doesn’t inherit a stale feedID/externalID from the cache or database. + feedSettingsCache[feed.url] = nil + feedSettingsDatabase.deleteSettings(for: feed.url) + } + public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { Task { @MainActor in do { diff --git a/Modules/Account/Sources/Account/FeedSettingsDatabase.swift b/Modules/Account/Sources/Account/FeedSettingsDatabase.swift index 313aa53b4..0b6d6319e 100644 --- a/Modules/Account/Sources/Account/FeedSettingsDatabase.swift +++ b/Modules/Account/Sources/Account/FeedSettingsDatabase.swift @@ -209,6 +209,14 @@ final class FeedSettingsDatabase: Sendable { } } + // MARK: - Deletion + + func deleteSettings(for feedURL: String) { + serialDispatchQueue.async { + self.database.executeUpdate("DELETE FROM feedSettings WHERE feedURL = ?;", withArgumentsIn: [feedURL]) + } + } + // MARK: - Cleanup on launch func deleteSettingsForFeedsNotIn(_ feedURLs: Set) { diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 8bcf73361..10b265844 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -243,6 +243,7 @@ public enum FeedbinAccountDelegateError: String, Error, Sendable { if let subscriptionID = feed.externalID { do { try await caller.deleteSubscription(subscriptionID: subscriptionID) + account.clearFeedSettings(feed) } catch { Self.logger.error("Feedbin: Remove feed error: \(error.localizedDescription)") postSyncError(error, account: account, operation: "Removing feed") @@ -957,6 +958,7 @@ private extension FeedbinAccountDelegate { postSyncError(error, account: account, operation: "Removing feed") } + account.clearFeedSettings(feed) account.removeAllInstancesOfFeedFromTreeAtAllLevels(feed) } diff --git a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift index 250d2317d..9ab5a9219 100644 --- a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift +++ b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift @@ -410,6 +410,7 @@ import os do { try await caller.deleteFeed(feedID: feedID, folder: folderName) + account.clearFeedSettings(feed) account.removeAllInstancesOfFeedFromTreeAtAllLevels(feed) } catch { throw AccountError.wrapped(error, account) diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 7b11ad8db..e7cbcf031 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -280,6 +280,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { do { try await caller.deleteSubscription(subscriptionID: subscriptionID) + account.clearFeedSettings(feed) refreshProgress.completeTask() } catch { @@ -376,6 +377,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { do { try await caller.deleteSubscription(subscriptionID: subscriptionID) + account.clearFeedSettings(feed) account.removeAllInstancesOfFeedFromTreeAtAllLevels(feed) } catch { Self.logger.error("ReaderAPIAccountDelegate: removeFeed - error: \(error.localizedDescription)") @@ -631,6 +633,7 @@ private extension ReaderAPIAccountDelegate { for folder in folders { for feed in folder.topLevelFeeds { if !subFeedIds.contains(feed.feedID) { + account.clearFeedSettings(feed) folder.removeFeedFromTreeAtTopLevel(feed) } } @@ -639,6 +642,7 @@ private extension ReaderAPIAccountDelegate { for feed in account.topLevelFeeds { if !subFeedIds.contains(feed.feedID) { + account.clearFeedSettings(feed) account.removeFeedFromTreeAtTopLevel(feed) } }