Change to use async fetch for major account changes

This commit is contained in:
Maurice Parker 2019-08-21 15:58:55 -05:00
parent 2719772701
commit af98311c63
1 changed files with 18 additions and 7 deletions

View File

@ -270,14 +270,14 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
@objc func accountStateDidChange(_ note: Notification) {
if timelineFetcherContainsAnyPseudoFeed() {
fetchAndReplaceArticlesSync()
fetchAndReplaceArticlesAsync()
}
rebuildBackingStores()
}
@objc func accountsDidChange(_ note: Notification) {
if timelineFetcherContainsAnyPseudoFeed() {
fetchAndReplaceArticlesSync()
fetchAndReplaceArticlesAsync()
}
rebuildBackingStores()
}
@ -916,8 +916,6 @@ private extension AppCoordinator {
}
}
// MARK: Fetching Articles
func queueFetchAndMergeArticles() {
fetchAndMergeArticlesQueue.add(self, #selector(fetchAndMergeArticles))
}
@ -946,6 +944,11 @@ private extension AppCoordinator {
}
func cancelPendingAsyncFetches() {
fetchSerialNumber += 1
fetchRequestQueue.cancelAllRequests()
}
func fetchAndReplaceArticlesSync() {
// To be called when the user has made a change of selection in the sidebar.
// It blocks the main thread, so that theres no async delay,
@ -960,9 +963,17 @@ private extension AppCoordinator {
replaceArticles(with: fetchedArticles)
}
func cancelPendingAsyncFetches() {
fetchSerialNumber += 1
fetchRequestQueue.cancelAllRequests()
func fetchAndReplaceArticlesAsync() {
// To be called when we need to do an entire fetch, but an async delay is okay.
// Example: we have the Today feed selected, and the calendar day just changed.
cancelPendingAsyncFetches()
guard let timelineFetcher = timelineFetcher else {
emptyTheTimeline()
return
}
fetchUnsortedArticlesAsync(for: [timelineFetcher]) { [weak self] (articles) in
self?.replaceArticles(with: articles)
}
}
func fetchUnsortedArticlesSync(for representedObjects: [Any]) -> Set<Article> {