From 779d24ee22b6126b8b4b964bf88147effc5c5a06 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 14 Oct 2024 22:32:39 -0700 Subject: [PATCH] =?UTF-8?q?Skip=20downloading=20favicons=20for=20a=20home?= =?UTF-8?q?=20page=20if=20it=E2=80=99s=20already=20in=20progress.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Images/Favicons/FaviconDownloader.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) 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.