diff --git a/Modules/Images/Sources/Images/Favicons/FaviconDownloader.swift b/Modules/Images/Sources/Images/Favicons/FaviconDownloader.swift index 64ebf4b31..20a61e313 100644 --- a/Modules/Images/Sources/Images/Favicons/FaviconDownloader.swift +++ b/Modules/Images/Sources/Images/Favicons/FaviconDownloader.swift @@ -37,6 +37,8 @@ public protocol FaviconDownloaderDelegate { private var remainingFaviconURLs = [String: ArraySlice]() // homePageURL: array of faviconURLs that haven't been checked yet private var currentHomePageHasOnlyFaviconICO = false + private var homePageURLsInProgress = Set() + 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.