From 8e54c93c6f09cb28754f3953c68169db8dc5d62d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 26 Nov 2024 21:04:53 -0800 Subject: [PATCH] Remove throttled feeds support. --- .../LocalAccount/LocalAccountRefresher.swift | 72 +------------------ 1 file changed, 3 insertions(+), 69 deletions(-) diff --git a/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift b/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift index ce40fa352..9b8dda747 100644 --- a/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift +++ b/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift @@ -29,16 +29,12 @@ final class LocalAccountRefresher { }() public func refreshFeeds(_ feeds: Set, completion: (() -> Void)? = nil) { - - let feedsToDownload = feedsWithThrottledHostsRemovedIfNeeded(feeds) - - guard !feedsToDownload.isEmpty else { + guard !feeds.isEmpty else { completion?() return } - self.completion = completion - downloadSession.downloadObjects(feedsToDownload as NSSet) + downloadSession.downloadObjects(feeds as NSSet) } public func suspend() { @@ -62,13 +58,8 @@ extension LocalAccountRefresher: DownloadSessionDelegate { guard let url = URL(string: feed.url) else { return nil } - - var request = URLRequest(url: url) - if let conditionalGetInfo = feed.conditionalGetInfo { - conditionalGetInfo.addRequestHeadersToURLRequest(&request) - } - return request + return URLRequest(url: url) } func downloadSession(_ downloadSession: DownloadSession, downloadDidCompleteForRepresentedObject representedObject: AnyObject, response: URLResponse?, data: Data, error: NSError?, completion: @escaping () -> Void) { @@ -105,9 +96,6 @@ extension LocalAccountRefresher: DownloadSessionDelegate { account.update(feed, with: parsedFeed) { result in if case .success(let articleChanges) = result { - if let httpResponse = response as? HTTPURLResponse { - feed.conditionalGetInfo = HTTPConditionalGetInfo(urlResponse: httpResponse) - } feed.contentHash = dataHash self.delegate?.localAccountRefresher(self, requestCompletedFor: feed) self.delegate?.localAccountRefresher(self, articleChanges: articleChanges) { @@ -162,60 +150,6 @@ extension LocalAccountRefresher: DownloadSessionDelegate { } } -// MARK: - Throttled Hosts - -private extension LocalAccountRefresher { - - // We want to support openrss.org, and possibly other domains in the future, - // by calling their servers no more often than timeIntervalBetweenThrottledHostsReads. - // We store the last read in UserDefaults. - static let lastReadOfThrottledHostsDefaultsKey = "lastReadOfThrottledHosts" - static let timeIntervalBetweenThrottledHostsReads: TimeInterval = 60 * 60 // One hour - - func feedsWithThrottledHostsRemovedIfNeeded(_ feeds: Set) -> Set { - - let currentDate = Date() - let lastReadOfThrottledHostsDate = UserDefaults.standard.object(forKey: Self.lastReadOfThrottledHostsDefaultsKey) as? Date ?? Date.distantPast - let timeIntervalSinceLastReadOfThrottledHosts = currentDate.timeIntervalSince(lastReadOfThrottledHostsDate) - - let shouldReadThrottledHosts = timeIntervalSinceLastReadOfThrottledHosts > (Self.timeIntervalBetweenThrottledHostsReads) - - if shouldReadThrottledHosts { - UserDefaults.standard.set(currentDate, forKey: Self.lastReadOfThrottledHostsDefaultsKey) - return feeds - } - - return feeds.filter { !feedIsFromThrottledDomain($0) } - } - - static let throttledHosts = ["openrss.org"] - - func feedIsFromThrottledDomain(_ feed: WebFeed) -> Bool { - - guard let url = URL(unicodeString: feed.url) else { - return false - } - - return urlIsThrottledDomain(url) - } - - func urlIsThrottledDomain(_ url: URL) -> Bool { - - guard let host = url.host() else { - return false - } - let lowerCaseHost = host.lowercased() - - for throttledHost in Self.throttledHosts { - if lowerCaseHost.contains(throttledHost) { - return true - } - } - - return false - } -} - // MARK: - Utility private extension Data {