From 6acb373d2fbb199e03dab412d3f8b0fe60c7ab80 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 31 Oct 2026 14:29:58 -0700 Subject: [PATCH] =?UTF-8?q?Stop=20recording=20=E2=80=9Cno=20favicon?= =?UTF-8?q?=E2=80=9D=20for=20five=20days=20after=20a=20transient=20failure?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/Images/Sources/Images/FaviconDownloader.swift | 8 ++++---- .../Images/Sources/Images/SingleFaviconDownloader.swift | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Modules/Images/Sources/Images/FaviconDownloader.swift b/Modules/Images/Sources/Images/FaviconDownloader.swift index 86ec18784..74cb15231 100644 --- a/Modules/Images/Sources/Images/FaviconDownloader.swift +++ b/Modules/Images/Sources/Images/FaviconDownloader.swift @@ -146,7 +146,7 @@ extension Notification.Name { // If the site explicitly specifies favicon.ico, it will appear twice. self.currentHomePageHasOnlyFaviconICO = faviconURLs.count == 1 self.remainingFaviconURLs[url] = faviconURLs[...] - downloadNextFavicon(forHomePageURL: url) + downloadNextFavicon(forHomePageURL: url, lastFailureWasTransient: false) } return nil @@ -165,7 +165,7 @@ extension Notification.Name { } guard singleFaviconDownloader.iconImage != nil else { if remainingFaviconURLs[homePageURL] != nil { - downloadNextFavicon(forHomePageURL: homePageURL) + downloadNextFavicon(forHomePageURL: homePageURL, lastFailureWasTransient: singleFaviconDownloader.lastFailureWasTransient) } return } @@ -243,7 +243,7 @@ private extension FaviconDownloader { // A skipped candidate advances to the next one — otherwise the queue // would stall and the remaining candidates would never be tried. // - func downloadNextFavicon(forHomePageURL homePageURL: String) { + func downloadNextFavicon(forHomePageURL homePageURL: String, lastFailureWasTransient: Bool) { while let faviconURL = remainingFaviconURLs[homePageURL]?.first { remainingFaviconURLs[homePageURL] = remainingFaviconURLs[homePageURL]?.dropFirst() if canAttemptDownload(faviconURL) { @@ -253,7 +253,7 @@ private extension FaviconDownloader { } remainingFaviconURLs[homePageURL] = nil - if currentHomePageHasOnlyFaviconICO { + if currentHomePageHasOnlyFaviconICO && !lastFailureWasTransient { ImageDatabase.shared.saveHomePageFavicon(homePageURL: homePageURL, faviconURL: nil) } } diff --git a/Modules/Images/Sources/Images/SingleFaviconDownloader.swift b/Modules/Images/Sources/Images/SingleFaviconDownloader.swift index 17b26194b..c7a35b6e1 100644 --- a/Modules/Images/Sources/Images/SingleFaviconDownloader.swift +++ b/Modules/Images/Sources/Images/SingleFaviconDownloader.swift @@ -22,6 +22,7 @@ extension Notification.Name { public let homePageURL: String? public var iconImage: IconImage? + private(set) var lastFailureWasTransient = false private static let retryInterval: TimeInterval = 30 * 60 // 30 minutes @@ -60,7 +61,9 @@ private extension SingleFaviconDownloader { func findFavicon() async { let kind = ActivityKind.downloadFavicon(faviconURL: faviconURL) - if let storedData = try? await DownloadedImageCache.shared.imageData(for: faviconURL, downloadPriority: nil, checksForUpdates: true, activityOwner: .faviconDownloader, activityKind: kind, activityDetail: homePageURL) { + lastFailureWasTransient = false + do throws(ImageDownloadError) { + let storedData = try await DownloadedImageCache.shared.imageData(for: faviconURL, downloadPriority: nil, checksForUpdates: true, activityOwner: .faviconDownloader, activityKind: kind, activityDetail: homePageURL) // DownloadedImageCache records download failures, but can’t know whether the data decodes as an icon. if let image = await Self.iconImage(storedData, maxPixelSize: RSImage.maxIconPixelSize) { iconImage = IconImage(image) @@ -68,6 +71,9 @@ private extension SingleFaviconDownloader { } else { ImageDatabase.shared.recordFailure(url: faviconURL, statusCode: nil) } + } catch { + // A non-image response usually means the site has no favicon at this URL. + lastFailureWasTransient = error.isTransient && !error.decodingFailed } postDidLoadFaviconNotification() }