Add feeds all in one go when processing Feedbin subscriptions. This is a performance enhancement.

This commit is contained in:
Brent Simmons 2019-10-06 12:37:46 -07:00
parent 1613a374d2
commit 50276233d1
2 changed files with 17 additions and 7 deletions

View File

@ -722,21 +722,28 @@ private extension FeedbinAccountDelegate {
}
// Add any feeds we don't have and update any we do
var subscriptionsToAdd = Set<FeedbinSubscription>()
subscriptions.forEach { subscription in
let subFeedId = String(subscription.feedID)
if let feed = account.existingFeed(withFeedID: subFeedId) {
feed.name = subscription.name
// If the name has been changed on the server remove the locally edited name
feed.editedName = nil
feed.homePageURL = subscription.homePageURL
feed.subscriptionID = String(subscription.subscriptionID)
} else {
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: subFeedId, homePageURL: subscription.homePageURL)
feed.subscriptionID = String(subscription.subscriptionID)
account.addFeed(feed)
}
else {
subscriptionsToAdd.insert(subscription)
}
}
// Actually add subscriptions all in one go, so we dont trigger various rebuilding things that Account does.
subscriptionsToAdd.forEach { subscription in
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: String(subscription.feedID), homePageURL: subscription.homePageURL)
feed.subscriptionID = String(subscription.subscriptionID)
account.addFeed(feed)
}
}

View File

@ -10,7 +10,7 @@ import Foundation
import RSCore
import RSParser
struct FeedbinSubscription: Codable {
struct FeedbinSubscription: Hashable, Codable {
let subscriptionID: Int
let feedID: Int
@ -26,6 +26,9 @@ struct FeedbinSubscription: Codable {
case homePageURL = "site_url"
}
public func hash(into hasher: inout Hasher) {
hasher.combine(subscriptionID)
}
}
struct FeedbinCreateSubscription: Codable {