From d40eaed1f53def04eba2d4b21a93be8c4af76d5b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 5 Feb 2020 21:23:23 -0800 Subject: [PATCH] Begin moving the MainThreadOperationQueue from Account to ArticlesDatabase. --- Frameworks/Account/Account.swift | 13 +++---------- Frameworks/ArticlesDatabase/ArticlesDatabase.swift | 7 ++----- iOS/Settings/AddAccountViewController.swift | 2 +- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 3e24e4daa..f3d418c5c 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -1277,27 +1277,20 @@ private extension Account { func fetchAllUnreadCounts() { fetchingAllUnreadCounts = true - operationQueue.cancelOperations(named: OperationName.FetchAllUnreadCounts) - - let operation = database.createFetchAllUnreadCountsOperation() - operation.name = OperationName.FetchAllUnreadCounts - operation.completionBlock = { operation in - let fetchOperation = operation as! FetchAllUnreadCountsOperation - guard let unreadCountDictionary = fetchOperation.unreadCountDictionary else { + database.fetchAllUnreadCounts { (result) in + guard let unreadCountDictionary = try? result.get() else { return } self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: self.flattenedWebFeeds()) self.fetchingAllUnreadCounts = false self.updateUnreadCount() - + if !self.isUnreadCountsInitialized { self.isUnreadCountsInitialized = true self.postUnreadCountDidInitializeNotification() } } - - operationQueue.add(operation) } func processUnreadCounts(unreadCountDictionary: UnreadCountDictionary, feeds: Set) { diff --git a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift index 4e7d9f787..7d7d0fa2d 100644 --- a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift +++ b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift @@ -138,8 +138,10 @@ public final class ArticlesDatabase { // MARK: - Unread Counts + /// Fetch all non-zero unread counts. public func fetchAllUnreadCounts(_ completion: @escaping UnreadCountDictionaryCompletionBlock) { let operation = FetchAllUnreadCountsOperation(databaseQueue: queue, cutoffDate: articlesTable.articleCutoffDate) + operationQueue.cancelOperations(named: operation.name!) operation.completionBlock = { operation in let fetchOperation = operation as! FetchAllUnreadCountsOperation completion(fetchOperation.result) @@ -203,11 +205,6 @@ public final class ArticlesDatabase { operationQueue.cancelAllOperations() } - /// Create an operation that fetches all non-zero unread counts. - public func createFetchAllUnreadCountsOperation() -> FetchAllUnreadCountsOperation { - return FetchAllUnreadCountsOperation(databaseQueue: queue, cutoffDate: articlesTable.articleCutoffDate) - } - /// Create an operation that fetches the unread count for a single given feedID. public func createFetchFeedUnreadCountOperation(feedID: String) -> FetchFeedUnreadCountOperation { return FetchFeedUnreadCountOperation(feedID: feedID, databaseQueue: queue, cutoffDate: articlesTable.articleCutoffDate) diff --git a/iOS/Settings/AddAccountViewController.swift b/iOS/Settings/AddAccountViewController.swift index e9c7ba678..abe901c63 100644 --- a/iOS/Settings/AddAccountViewController.swift +++ b/iOS/Settings/AddAccountViewController.swift @@ -49,7 +49,7 @@ class AddAccountViewController: UITableViewController, AddAccountDismissDelegate let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly) addAccount.delegate = self addAccount.presentationAnchor = self.view.window! - MainThreadOperationQueue.shared.addOperation(addAccount) + MainThreadOperationQueue.shared.add(addAccount) case 3: let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "FeedWranglerAccountNavigationViewController") as! UINavigationController navController.modalPresentationStyle = .currentContext