From 113fe79301821db693f0cb3b9cce831aa0e0ba33 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 6 Jul 2019 17:08:02 -0700 Subject: [PATCH 1/7] Update RSCore. --- submodules/RSCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/RSCore b/submodules/RSCore index 111690033..277c64868 160000 --- a/submodules/RSCore +++ b/submodules/RSCore @@ -1 +1 @@ -Subproject commit 111690033354afc1cf57e37a326c344a0fe93b77 +Subproject commit 277c64868a4a7464f32bbd2b063af3b7736904a3 From a5bf148d82f83a0126f4459496abd5a78128d13b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 7 Jul 2019 13:42:24 -0700 Subject: [PATCH 2/7] =?UTF-8?q?Make=20Transport=20callbacks=20run=20on=20t?= =?UTF-8?q?he=20main=20thread,=20which=20is=20consistent=20with=20NetNewsW?= =?UTF-8?q?ire=E2=80=99s=20general=20pattern=20for=20these=20types=20of=20?= =?UTF-8?q?callbacks.=20This=20helps=20avoid=20situations=20where=20we=20t?= =?UTF-8?q?ouch=20model=20objects=20(which=20are=20main-thread-only)=20on?= =?UTF-8?q?=20a=20background=20thread.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 3b7d7894a..961c12263 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -816,9 +816,7 @@ private extension FeedbinAccountDelegate { for feed in account.flattenedFeeds() { for (key, value) in iconDict { if feed.homePageURL?.contains(key) ?? false { - DispatchQueue.main.sync { - feed.faviconURL = value - } + feed.faviconURL = value break } } From daaf44d67f79a0c87d5dc6d89b52d09411243891 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 7 Jul 2019 13:45:28 -0700 Subject: [PATCH 3/7] Update RSWeb. --- submodules/RSWeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/RSWeb b/submodules/RSWeb index 4f8844750..b5e10264d 160000 --- a/submodules/RSWeb +++ b/submodules/RSWeb @@ -1 +1 @@ -Subproject commit 4f8844750e9c25b0e43f9ead3de582d32a1321de +Subproject commit b5e10264d46ca74eec76f181e4084ca6e7985fae From 590961fb2c8ac40957fbc20205b05738e0be7efd Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 7 Jul 2019 14:01:44 -0700 Subject: [PATCH 4/7] =?UTF-8?q?Add=20comment=20that=20Account=20is=20main-?= =?UTF-8?q?thread-only,=20and=20assert=20that=20we=E2=80=99re=20on=20the?= =?UTF-8?q?=20main=20thread=20in=20flattenedFeeds().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/Account/Account.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index dfa0ea452..80713ef82 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -17,6 +17,8 @@ import RSParser import ArticlesDatabase import RSWeb +// Main thread only. + public extension Notification.Name { static let AccountRefreshDidBegin = Notification.Name(rawValue: "AccountRefreshDidBegin") static let AccountRefreshDidFinish = Notification.Name(rawValue: "AccountRefreshDidFinish") @@ -636,6 +638,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, // MARK: - Container public func flattenedFeeds() -> Set { + assert(Thread.isMainThread) if flattenedFeedsNeedUpdate { updateFlattenedFeeds() } From 1e82ad48451a2971e6e425cbc4f07c56b7142f91 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 7 Jul 2019 14:05:27 -0700 Subject: [PATCH 5/7] Note that AccountManager is main thread only. Add an assert in a strategic location (activeAccounts property). --- Frameworks/Account/AccountManager.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Frameworks/Account/AccountManager.swift b/Frameworks/Account/AccountManager.swift index efe7305f0..acb53cd5b 100644 --- a/Frameworks/Account/AccountManager.swift +++ b/Frameworks/Account/AccountManager.swift @@ -10,6 +10,8 @@ import Foundation import RSCore import Articles +// Main thread only. + public extension Notification.Name { static let AccountsDidChange = Notification.Name(rawValue: "AccountsDidChange") } @@ -51,6 +53,7 @@ public final class AccountManager: UnreadCountProvider { } public var activeAccounts: [Account] { + assert(Thread.isMainThread) return Array(accountsDictionary.values.filter { $0.isActive }) } From 597c57e61c4d3a68d29439307887c62cb520f23b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 7 Jul 2019 14:24:50 -0700 Subject: [PATCH 6/7] =?UTF-8?q?Remove=20references=20to=20DispatchQueue.ma?= =?UTF-8?q?in.sync=20and=20assert=20that=20we=E2=80=99re=20on=20the=20main?= =?UTF-8?q?=20thread.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Feedbin/FeedbinAccountDelegate.swift | 76 +++++++------------ 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 961c12263..6f2dfa376 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -592,8 +592,8 @@ private extension FeedbinAccountDelegate { } func syncFolders(_ account: Account, _ tags: [FeedbinTag]?) { - guard let tags = tags else { return } + assert(Thread.isMainThread) os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count) @@ -603,13 +603,11 @@ private extension FeedbinAccountDelegate { if let folders = account.folders { folders.forEach { folder in if !tagNames.contains(folder.name ?? "") { - DispatchQueue.main.sync { - for feed in folder.topLevelFeeds { - account.addFeed(feed) - clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") - } - account.removeFolder(folder) + for feed in folder.topLevelFeeds { + account.addFeed(feed) + clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") } + account.removeFolder(folder) } } } @@ -625,9 +623,7 @@ private extension FeedbinAccountDelegate { // Make any folders Feedbin has, but we don't tagNames.forEach { tagName in if !folderNames.contains(tagName) { - DispatchQueue.main.sync { - _ = account.ensureFolder(with: tagName) - } + _ = account.ensureFolder(with: tagName) } } @@ -681,7 +677,8 @@ private extension FeedbinAccountDelegate { func syncFeeds(_ account: Account, _ subscriptions: [FeedbinSubscription]?) { guard let subscriptions = subscriptions else { return } - + assert(Thread.isMainThread) + os_log(.debug, log: log, "Syncing feeds with %ld subscriptions.", subscriptions.count) let subFeedIds = subscriptions.map { String($0.feedID) } @@ -691,9 +688,7 @@ private extension FeedbinAccountDelegate { for folder in folders { for feed in folder.topLevelFeeds { if !subFeedIds.contains(feed.feedID) { - DispatchQueue.main.sync { - folder.removeFeed(feed) - } + folder.removeFeed(feed) } } } @@ -701,9 +696,7 @@ private extension FeedbinAccountDelegate { for feed in account.topLevelFeeds { if !subFeedIds.contains(feed.feedID) { - DispatchQueue.main.sync { - account.removeFeed(feed) - } + account.removeFeed(feed) } } @@ -712,27 +705,24 @@ private extension FeedbinAccountDelegate { let subFeedId = String(subscription.feedID) - DispatchQueue.main.sync { - if let feed = account.idToFeedDictionary[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) - } + if let feed = account.idToFeedDictionary[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) } - } - } func syncTaggings(_ account: Account, _ taggings: [FeedbinTagging]?) { guard let taggings = taggings else { return } + assert(Thread.isMainThread) os_log(.debug, log: log, "Syncing taggings with %ld taggings.", taggings.count) @@ -766,11 +756,9 @@ private extension FeedbinAccountDelegate { // Move any feeds not in the folder to the account for feed in folder.topLevelFeeds { if !taggingFeedIDs.contains(feed.feedID) { - DispatchQueue.main.sync { - folder.removeFeed(feed) - clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") - account.addFeed(feed) - } + folder.removeFeed(feed) + clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") + account.addFeed(feed) } } @@ -783,10 +771,8 @@ private extension FeedbinAccountDelegate { guard let feed = account.idToFeedDictionary[taggingFeedID] else { continue } - DispatchQueue.main.sync { - saveFolderRelationship(for: feed, withFolderName: folderName, id: String(tagging.taggingID)) - folder.addFeed(feed) - } + saveFolderRelationship(for: feed, withFolderName: folderName, id: String(tagging.taggingID)) + folder.addFeed(feed) } } @@ -795,14 +781,11 @@ private extension FeedbinAccountDelegate { let taggedFeedIDs = Set(taggings.map { String($0.feedID) }) // Remove all feeds from the account container that have a tag - DispatchQueue.main.sync { - for feed in account.topLevelFeeds { - if taggedFeedIDs.contains(feed.feedID) { - account.removeFeed(feed) - } + for feed in account.topLevelFeeds { + if taggedFeedIDs.contains(feed.feedID) { + account.removeFeed(feed) } } - } func syncFavicons(_ account: Account, _ icons: [FeedbinIcon]?) { @@ -821,7 +804,6 @@ private extension FeedbinAccountDelegate { } } } - } From a25436cea18a9ccc2dec7a7249cc55af84193a58 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 7 Jul 2019 14:25:15 -0700 Subject: [PATCH 7/7] Update RSWeb. --- submodules/RSWeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/RSWeb b/submodules/RSWeb index b5e10264d..b236f5762 160000 --- a/submodules/RSWeb +++ b/submodules/RSWeb @@ -1 +1 @@ -Subproject commit b5e10264d46ca74eec76f181e4084ca6e7985fae +Subproject commit b236f57627cb8aa3feac835689754d4863eb1788