Skip downloading favicons for a home page if it’s already in progress.

This commit is contained in:
Brent Simmons
2024-10-14 22:32:39 -07:00
parent 69b30f5012
commit 779d24ee22

View File

@@ -37,6 +37,8 @@ public protocol FaviconDownloaderDelegate {
private var remainingFaviconURLs = [String: ArraySlice<String>]() // homePageURL: array of faviconURLs that haven't been checked yet
private var currentHomePageHasOnlyFaviconICO = false
private var homePageURLsInProgress = Set<String>()
private var homePageToFaviconURLCache = [String: String]() //homePageURL: faviconURL
private var homePageToFaviconURLCachePath: URL
private var homePageToFaviconURLCacheDirty = false {
@@ -144,8 +146,17 @@ public protocol FaviconDownloaderDelegate {
return favicon(with: faviconURL, homePageURL: url)
}
guard !homePageURLsInProgress.contains(homePageURL) else {
return nil
}
homePageURLsInProgress.insert(homePageURL)
Task { @MainActor in
defer {
homePageURLsInProgress.remove(homePageURL)
}
if let faviconURLs = await findFaviconURLs(with: url) {
// If the site explicitly specifies favicon.ico, it will appear twice.