From 776adcb63b30bcb0b70656cbb0f60c38797dbc58 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 15 Oct 2024 20:50:42 -0700 Subject: [PATCH] =?UTF-8?q?Stop=20saving=20the=20homePagesWithNoIconURLCac?= =?UTF-8?q?he=20on=20disk=20=E2=80=94=C2=A0because=20it=20can=20become=20w?= =?UTF-8?q?rong=20when=20sites=20do=20add=20feed=20icons.=20This=20way=20i?= =?UTF-8?q?t=E2=80=99s=20dropped=20between=20runs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Images/FeedIconDownloader.swift | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/Modules/Images/Sources/Images/FeedIconDownloader.swift b/Modules/Images/Sources/Images/FeedIconDownloader.swift index 143527a94..d80a47fe4 100644 --- a/Modules/Images/Sources/Images/FeedIconDownloader.swift +++ b/Modules/Images/Sources/Images/FeedIconDownloader.swift @@ -45,13 +45,6 @@ public extension Notification.Name { } private var homePagesWithNoIconURLCache = Set() - private var homePagesWithNoIconURLCachePath: URL - private var homePagesWithNoIconURLCacheDirty = false { - didSet { - queueHomePagesWithNoIconURLCacheIfNeeded() - } - } - private var homePagesWithUglyIcons: Set = { return Set(["https://www.macsparky.com/", "https://xkcd.com/"]) }() @@ -65,10 +58,8 @@ public extension Notification.Name { self.feedURLToIconURLCachePath = folder.appendingPathComponent("FeedURLToIconURLCache.plist") self.homePageToIconURLCachePath = folder.appendingPathComponent("HomePageToIconURLCache.plist") - self.homePagesWithNoIconURLCachePath = folder.appendingPathComponent("HomePagesWithNoIconURLCache.plist") loadFeedURLToIconURLCache() loadHomePageToIconURLCache() - loadHomePagesWithNoIconURLCache() NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: imageDownloader) } @@ -151,12 +142,6 @@ public extension Notification.Name { saveHomePageToIconURLCache() } } - - @objc func saveHomePagesWithNoIconURLCacheIfNeeded() { - if homePagesWithNoIconURLCacheDirty { - saveHomePagesWithNoIconURLCache() - } - } } private extension FeedIconDownloader { @@ -210,7 +195,6 @@ private extension FeedIconDownloader { func cacheIconURL(for homePageURL: String, _ iconURL: String) { homePagesWithNoIconURLCache.remove(homePageURL) - homePagesWithNoIconURLCacheDirty = true homePageToIconURLCache[homePageURL] = iconURL homePageToIconURLCacheDirty = true } @@ -231,15 +215,6 @@ private extension FeedIconDownloader { homePageToIconURLCache = (try? decoder.decode([String: String].self, from: data)) ?? [String: String]() } - func loadHomePagesWithNoIconURLCache() { - guard let data = try? Data(contentsOf: homePagesWithNoIconURLCachePath) else { - return - } - let decoder = PropertyListDecoder() - let decoded = (try? decoder.decode([String].self, from: data)) ?? [String]() - homePagesWithNoIconURLCache = Set(decoded) - } - @MainActor func queueSaveFeedURLToIconURLCacheIfNeeded() { FeedIconDownloader.saveQueue.add(self, #selector(saveFeedURLToIconURLCacheIfNeeded)) } @@ -248,10 +223,6 @@ private extension FeedIconDownloader { FeedIconDownloader.saveQueue.add(self, #selector(saveHomePageToIconURLCacheIfNeeded)) } - @MainActor func queueHomePagesWithNoIconURLCacheIfNeeded() { - FeedIconDownloader.saveQueue.add(self, #selector(saveHomePagesWithNoIconURLCacheIfNeeded)) - } - func saveFeedURLToIconURLCache() { feedURLToIconURLCacheDirty = false @@ -277,17 +248,4 @@ private extension FeedIconDownloader { assertionFailure(error.localizedDescription) } } - - func saveHomePagesWithNoIconURLCache() { - homePagesWithNoIconURLCacheDirty = false - - let encoder = PropertyListEncoder() - encoder.outputFormat = .binary - do { - let data = try encoder.encode(Array(homePagesWithNoIconURLCache)) - try data.write(to: homePagesWithNoIconURLCachePath) - } catch { - assertionFailure(error.localizedDescription) - } - } }