Begin moving the MainThreadOperationQueue from Account to ArticlesDatabase.

This commit is contained in:
Brent Simmons 2020-02-05 21:23:23 -08:00
parent 2d33de1205
commit d40eaed1f5
3 changed files with 6 additions and 16 deletions

View File

@ -1277,13 +1277,8 @@ 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())
@ -1296,8 +1291,6 @@ private extension Account {
self.postUnreadCountDidInitializeNotification()
}
}
operationQueue.add(operation)
}
func processUnreadCounts(unreadCountDictionary: UnreadCountDictionary, feeds: Set<WebFeed>) {

View File

@ -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)

View File

@ -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