From 1cfafe301400ddb2e0f87cc8aaefa0ef5be3bc39 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 2 Oct 2019 23:05:35 -0700 Subject: [PATCH] =?UTF-8?q?Add=20feeds=20from=20Feedbin=20all=20in=20one?= =?UTF-8?q?=20go,=20which=20helps=20performance=20by=20not=20triggering=20?= =?UTF-8?q?Account=E2=80=99s=20rebuilding=20of=20its=20feedDictionary.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Account/Feedbin/FeedbinAccountDelegate.swift | 15 +++++++++++---- .../Account/Feedbin/FeedbinSubscription.swift | 5 ++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 1855d63c4..d831a3a99 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -728,6 +728,7 @@ private extension FeedbinAccountDelegate { } // Add any feeds we don't have and update any we do + var subscriptionsToAdd = Set() subscriptions.forEach { subscription in let subFeedId = String(subscription.feedID) @@ -738,11 +739,17 @@ private extension FeedbinAccountDelegate { 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 don’t 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) } } diff --git a/Frameworks/Account/Feedbin/FeedbinSubscription.swift b/Frameworks/Account/Feedbin/FeedbinSubscription.swift index 8d3ca1109..feac0e7dd 100644 --- a/Frameworks/Account/Feedbin/FeedbinSubscription.swift +++ b/Frameworks/Account/Feedbin/FeedbinSubscription.swift @@ -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 {