mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Override existingFeed(withURL url: String) from Container protocol for performance reasons. Use a dictionary to lookup a feed more quickly than by looping through the feeds.
This commit is contained in:
@@ -174,7 +174,15 @@ public enum FetchType {
|
||||
}
|
||||
return _externalIDToFeedDictionary
|
||||
}
|
||||
|
||||
|
||||
private var _urlToFeedDictionary = [String: Feed]()
|
||||
var urlToFeedDictionary: [String: Feed] {
|
||||
if feedDictionariesNeedUpdate {
|
||||
rebuildFeedDictionaries()
|
||||
}
|
||||
return _urlToFeedDictionary
|
||||
}
|
||||
|
||||
var flattenedFeedURLs: Set<String> {
|
||||
return Set(flattenedFeeds().map({ $0.url }))
|
||||
}
|
||||
@@ -1341,16 +1349,19 @@ private extension Account {
|
||||
func rebuildFeedDictionaries() {
|
||||
var idDictionary = [String: Feed]()
|
||||
var externalIDDictionary = [String: Feed]()
|
||||
var urlToFeedDictionary = [String: Feed]()
|
||||
|
||||
for feed in flattenedFeeds() {
|
||||
idDictionary[feed.feedID] = feed
|
||||
if let externalID = feed.externalID {
|
||||
externalIDDictionary[externalID] = feed
|
||||
}
|
||||
urlToFeedDictionary[feed.url] = feed
|
||||
}
|
||||
|
||||
_idToFeedDictionary = idDictionary
|
||||
_externalIDToFeedDictionary = externalIDDictionary
|
||||
_urlToFeedDictionary = urlToFeedDictionary
|
||||
feedDictionariesNeedUpdate = false
|
||||
}
|
||||
|
||||
@@ -1510,7 +1521,10 @@ extension Account {
|
||||
public func existingFeed(withExternalID externalID: String) -> Feed? {
|
||||
return externalIDToFeedDictionary[externalID]
|
||||
}
|
||||
|
||||
|
||||
public func existingFeed(withURL url: String) -> Feed? {
|
||||
urlToFeedDictionary[url]
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - OPMLRepresentable
|
||||
|
||||
Reference in New Issue
Block a user