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() {
|
override func main() {
|
||||||
|
assert(Thread.isMainThread) // Needs to be on main thread because Feed is a main-thread-only model type.
|
||||||
guard !isCancelled else {
|
guard !isCancelled else {
|
||||||
didFinish()
|
didFinish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let group = DispatchGroup()
|
|
||||||
let allFeeds = organisedItemsProvider.allFeeds
|
let allFeeds = organisedItemsProvider.allFeeds
|
||||||
|
|
||||||
// os_log(.debug, log: log, "Begin updating %i feeds in collection \"%@\"", allFeeds.count, organisedItemsProvider.collection.label)
|
// 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 {
|
for feed in allFeeds {
|
||||||
guard let items = organisedItemsProvider.parsedItems(for: feed) else {
|
guard let items = organisedItemsProvider.parsedItems(for: feed) else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
group.enter()
|
feedIDsAndItems[feed.feedID] = items
|
||||||
// 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()
|
|
||||||
}
|
}
|
||||||
}
|
account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true) {
|
||||||
|
|
||||||
group.notify(qos: .userInitiated, queue: .main) {
|
|
||||||
// os_log(.debug, log: self.log, "Finished updating feeds in collection \"%@\"", self.organisedItemsProvider.collection.label)
|
// os_log(.debug, log: self.log, "Finished updating feeds in collection \"%@\"", self.organisedItemsProvider.collection.label)
|
||||||
self.didFinish()
|
self.didFinish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -866,32 +866,9 @@ private extension ReaderAPIAccountDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func processEntries(account: Account, entries: [ReaderAPIEntry]?, completion: @escaping (() -> Void)) {
|
func processEntries(account: Account, entries: [ReaderAPIEntry]?, completion: @escaping (() -> Void)) {
|
||||||
|
|
||||||
let parsedItems = mapEntriesToParsedItems(account: account, entries: entries)
|
let parsedItems = mapEntriesToParsedItems(account: account, entries: entries)
|
||||||
let parsedMap = Dictionary(grouping: parsedItems, by: { item in item.feedURL } )
|
let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) }
|
||||||
|
account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true, completion: completion)
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapEntriesToParsedItems(account: Account, entries: [ReaderAPIEntry]?) -> Set<ParsedItem> {
|
func mapEntriesToParsedItems(account: Account, entries: [ReaderAPIEntry]?) -> Set<ParsedItem> {
|
||||||
|
|
Loading…
Reference in New Issue