mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Remove throttled feeds support.
This commit is contained in:
@@ -29,16 +29,12 @@ final class LocalAccountRefresher {
|
||||
}()
|
||||
|
||||
public func refreshFeeds(_ feeds: Set<WebFeed>, 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<WebFeed>) -> Set<WebFeed> {
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user