diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 70d0fc977..cb200e9a1 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -18,6 +18,8 @@ import ArticlesDatabase import RSWeb import os.log +// Main thread only. + public extension Notification.Name { static let AccountRefreshDidBegin = Notification.Name(rawValue: "AccountRefreshDidBegin") static let AccountRefreshDidFinish = Notification.Name(rawValue: "AccountRefreshDidFinish") @@ -684,6 +686,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, // MARK: - Container public func flattenedFeeds() -> Set { + assert(Thread.isMainThread) if flattenedFeedsNeedUpdate { updateFlattenedFeeds() } 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 }) } diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 715cd275f..8086f3dd4 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -602,8 +602,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) @@ -613,13 +613,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) } } } @@ -635,9 +633,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) } } @@ -691,7 +687,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) } @@ -701,9 +698,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) } } } @@ -711,9 +706,7 @@ private extension FeedbinAccountDelegate { for feed in account.topLevelFeeds { if !subFeedIds.contains(feed.feedID) { - DispatchQueue.main.sync { - account.removeFeed(feed) - } + account.removeFeed(feed) } } @@ -722,27 +715,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) @@ -776,11 +766,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) } } @@ -793,10 +781,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) } } @@ -805,14 +791,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]?) { @@ -826,14 +809,11 @@ 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 } } } - } diff --git a/submodules/RSWeb b/submodules/RSWeb index afcbd0819..b236f5762 160000 --- a/submodules/RSWeb +++ b/submodules/RSWeb @@ -1 +1 @@ -Subproject commit afcbd0819c85b263acc892361ed840a9628eba4d +Subproject commit b236f57627cb8aa3feac835689754d4863eb1788