Use the new article saving function for both Feedly and ReaderAPI.
This commit is contained in:
parent
c04322990c
commit
7b09c86858
|
@ -23,29 +23,24 @@ final class FeedlyUpdateAccountFeedsWithItemsOperation: FeedlyOperation {
|
|||
}
|
||||
|
||||
override func main() {
|
||||
assert(Thread.isMainThread) // Needs to be on main thread because Feed is a main-thread-only model type.
|
||||
guard !isCancelled else {
|
||||
didFinish()
|
||||
return
|
||||
}
|
||||
|
||||
let group = DispatchGroup()
|
||||
let allFeeds = organisedItemsProvider.allFeeds
|
||||
|
||||
// os_log(.debug, log: log, "Begin updating %i feeds in collection \"%@\"", allFeeds.count, organisedItemsProvider.collection.label)
|
||||
|
||||
var feedIDsAndItems = [String: Set<ParsedItem>]()
|
||||
for feed in allFeeds {
|
||||
guard let items = organisedItemsProvider.parsedItems(for: feed) else {
|
||||
continue
|
||||
}
|
||||
group.enter()
|
||||
// os_log(.debug, log: log, "Updating %i items for feed \"%@\" in collection \"%@\"", items.count, feed.nameForDisplay, organisedItemsProvider.collection.label)
|
||||
|
||||
account.update(feed, parsedItems: items, defaultRead: true) {
|
||||
group.leave()
|
||||
feedIDsAndItems[feed.feedID] = items
|
||||
}
|
||||
}
|
||||
|
||||
group.notify(qos: .userInitiated, queue: .main) {
|
||||
account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true) {
|
||||
// os_log(.debug, log: self.log, "Finished updating feeds in collection \"%@\"", self.organisedItemsProvider.collection.label)
|
||||
self.didFinish()
|
||||
}
|
||||
|
|
|
@ -866,32 +866,9 @@ private extension ReaderAPIAccountDelegate {
|
|||
}
|
||||
|
||||
func processEntries(account: Account, entries: [ReaderAPIEntry]?, completion: @escaping (() -> Void)) {
|
||||
|
||||
let parsedItems = mapEntriesToParsedItems(account: account, entries: entries)
|
||||
let parsedMap = Dictionary(grouping: parsedItems, by: { item in item.feedURL } )
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
for (feedID, mapItems) in parsedMap {
|
||||
|
||||
group.enter()
|
||||
|
||||
if let feed = account.existingFeed(withFeedID: feedID) {
|
||||
DispatchQueue.main.async {
|
||||
account.update(feed, parsedItems: Set(mapItems), defaultRead: true) {
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
group.leave()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion()
|
||||
}
|
||||
|
||||
let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) }
|
||||
account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true, completion: completion)
|
||||
}
|
||||
|
||||
func mapEntriesToParsedItems(account: Account, entries: [ReaderAPIEntry]?) -> Set<ParsedItem> {
|
||||
|
|
Loading…
Reference in New Issue