Merge pull request #1137 from kielgillard/master
Feedly: removes redundant mapping of articles to feed IDs.
This commit is contained in:
commit
d2428e876b
|
@ -12,8 +12,7 @@ import os.log
|
|||
|
||||
protocol FeedlyParsedItemsByFeedProviding {
|
||||
var providerName: String { get }
|
||||
var allFeeds: Set<Feed> { get }
|
||||
func parsedItems(for feed: Feed) -> Set<ParsedItem>?
|
||||
var parsedItemsKeyedByFeedId: [String: Set<ParsedItem>] { get }
|
||||
}
|
||||
|
||||
/// Single responsibility is to group articles by their feeds.
|
||||
|
@ -22,15 +21,9 @@ final class FeedlyOrganiseParsedItemsByFeedOperation: FeedlyOperation, FeedlyPar
|
|||
private let entryProvider: FeedlyEntryProviding
|
||||
private let log: OSLog
|
||||
|
||||
var allFeeds: Set<Feed> {
|
||||
var parsedItemsKeyedByFeedId: [String : Set<ParsedItem>] {
|
||||
assert(Thread.isMainThread) // Needs to be on main thread because Feed is a main-thread-only model type.
|
||||
let keys = Set(itemsKeyedByFeedId.keys)
|
||||
return account.flattenedFeeds().filter { keys.contains($0.feedID) }
|
||||
}
|
||||
|
||||
func parsedItems(for feed: Feed) -> Set<ParsedItem>? {
|
||||
assert(Thread.isMainThread) // Needs to be on main thread because Feed is a main-thread-only model type.
|
||||
return itemsKeyedByFeedId[feed.feedID]
|
||||
return itemsKeyedByFeedId
|
||||
}
|
||||
|
||||
var providerName: String {
|
||||
|
|
|
@ -29,19 +29,10 @@ final class FeedlyUpdateAccountFeedsWithItemsOperation: FeedlyOperation {
|
|||
return
|
||||
}
|
||||
|
||||
let allFeeds = organisedItemsProvider.allFeeds
|
||||
let feedIDsAndItems = organisedItemsProvider.parsedItemsKeyedByFeedId
|
||||
|
||||
os_log(.debug, log: log, "Begin updating %i feeds for \"%@\"", allFeeds.count, organisedItemsProvider.providerName)
|
||||
|
||||
var feedIDsAndItems = [String: Set<ParsedItem>]()
|
||||
for feed in allFeeds {
|
||||
guard let items = organisedItemsProvider.parsedItems(for: feed) else {
|
||||
continue
|
||||
}
|
||||
feedIDsAndItems[feed.feedID] = items
|
||||
}
|
||||
account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true) {
|
||||
os_log(.debug, log: self.log, "Finished updating feeds for \"%@\"", self.organisedItemsProvider.providerName)
|
||||
os_log(.debug, log: self.log, "Updated %i feeds for \"%@\"", feedIDsAndItems.count, self.organisedItemsProvider.providerName)
|
||||
self.didFinish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue