From 39599a43f3bc8345e15b8413b8527e92b4b7def8 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Oct 2017 18:45:09 -0700 Subject: [PATCH] =?UTF-8?q?Make=20hasAtLeastOneFeed()=20a=20Container=20pr?= =?UTF-8?q?otocol=20function=20with=20a=20default=20implementation.=20Scra?= =?UTF-8?q?p=20Account=E2=80=99s=20feedIDDictionary,=20since=20it=E2=80=99?= =?UTF-8?q?s=20not=20needed.=20(Well,=20profiling=20may=20tell=20us=20late?= =?UTF-8?q?r=20to=20bring=20it=20back.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/Account/Account.swift | 18 ------------------ Frameworks/Account/AccountManager.swift | 2 +- Frameworks/Account/Container.swift | 19 ++++++++++++++++++- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index ffb5a4b45..10771270d 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -53,7 +53,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, let dataFolder: String let database: Database let delegate: AccountDelegate - var feedIDDictionary = [String: Feed]() var username: String? var saveTimer: Timer? @@ -106,12 +105,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } - var hasAtLeastOneFeed: Bool { - get { - return !feedIDDictionary.isEmpty - } - } - var supportsSubFolders: Bool { get { return delegate.supportsSubFolders @@ -215,7 +208,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, didAddFeed = true } - updateFeedIDDictionary() return didAddFeed // TODO } @@ -346,7 +338,6 @@ private extension Account { return } children = objects(with: childrenArray) - updateFeedIDDictionary() } func diskDictionary() -> NSDictionary { @@ -413,15 +404,6 @@ private extension Account { private extension Account { - func updateFeedIDDictionary() { - - var d = [String: Feed]() - for feed in flattenedFeeds() { - d[feed.feedID] = feed - } - feedIDDictionary = d - } - func topLevelObjectsContainsFeed(_ feed: Feed) -> Bool { return children.contains(where: { (object) -> Bool in diff --git a/Frameworks/Account/AccountManager.swift b/Frameworks/Account/AccountManager.swift index bc47c7dce..5be8ff9a7 100644 --- a/Frameworks/Account/AccountManager.swift +++ b/Frameworks/Account/AccountManager.swift @@ -101,7 +101,7 @@ public final class AccountManager: UnreadCountProvider { public func anyAccountHasAtLeastOneFeed() -> Bool { for account in accounts { - if account.hasAtLeastOneFeed { + if account.hasAtLeastOneFeed() { return true } } diff --git a/Frameworks/Account/Container.swift b/Frameworks/Account/Container.swift index 7192da2ed..7b8e006f9 100644 --- a/Frameworks/Account/Container.swift +++ b/Frameworks/Account/Container.swift @@ -19,7 +19,8 @@ extension NSNotification.Name { public protocol Container { var children: [AnyObject] { get } - + + func hasAtLeastOneFeed() -> Bool func objectIsChild(_ object: AnyObject) -> Bool //Recursive @@ -35,6 +36,22 @@ public protocol Container { public extension Container { + func hasAtLeastOneFeed() -> Bool { + + for child in children { + if let feed = child as? Feed { + return true + } + if let folder = child as? Folder { + if folder.hasAtLeastOneFeed() { + return true + } + } + } + + return false + } + func objectIsChild(_ object: AnyObject) -> Bool { for child in children {