Stop recording “no favicon” for five days after a transient failure.

This commit is contained in:
Brent Simmons committed 2026-10-31 14:29:58 -07:00
1 parent e7063cf68b
commit 6acb373d2f
2 files changed
+11 -5

No files matched your search

@@ -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.
// <https://github.com/Ranchero-Software/NetNewsWire/issues/4868>
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)
}
}
@@ -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()
}