From c580877a86acccbee47a88eac7558213fb042fdd Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 12 Sep 2020 18:09:42 -0500 Subject: [PATCH] Change to utilize ArticleFetchers instead of Feeds so that the single article fetcher stops getting filtered out. Issue #2416 --- .../Timeline/TimelineViewController.swift | 16 +++++------ Shared/Timeline/FetchRequestOperation.swift | 28 +++++++++---------- iOS/SceneCoordinator.swift | 4 +-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index d3e6f8fb4..1911ace3a 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -1129,19 +1129,19 @@ private extension TimelineViewController { func fetchUnsortedArticlesSync(for representedObjects: [Any]) -> Set
{ cancelPendingAsyncFetches() - let feeds = representedObjects.compactMap{ $0 as? Feed } - if feeds.isEmpty { + let fetchers = representedObjects.compactMap{ $0 as? ArticleFetcher } + if fetchers.isEmpty { return Set
() } var fetchedArticles = Set
() - for feed in feeds { - if feed.readFiltered(readFilterEnabledTable: readFilterEnabledTable) { - if let articles = try? feed.fetchUnreadArticles() { + for fetchers in fetchers { + if (fetchers as? Feed)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true { + if let articles = try? fetchers.fetchUnreadArticles() { fetchedArticles.formUnion(articles) } } else { - if let articles = try? feed.fetchArticles() { + if let articles = try? fetchers.fetchArticles() { fetchedArticles.formUnion(articles) } } @@ -1154,8 +1154,8 @@ private extension TimelineViewController { // if it’s been superseded by a newer fetch, or the timeline was emptied, etc., it won’t get called. precondition(Thread.isMainThread) cancelPendingAsyncFetches() - let feeds = representedObjects.compactMap { $0 as? Feed } - let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, feeds: feeds) { [weak self] (articles, operation) in + let fetchers = representedObjects.compactMap { $0 as? ArticleFetcher } + let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, fetchers: fetchers) { [weak self] (articles, operation) in precondition(Thread.isMainThread) guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else { return diff --git a/Shared/Timeline/FetchRequestOperation.swift b/Shared/Timeline/FetchRequestOperation.swift index e4b8cfbbd..74ba5d098 100644 --- a/Shared/Timeline/FetchRequestOperation.swift +++ b/Shared/Timeline/FetchRequestOperation.swift @@ -23,13 +23,13 @@ final class FetchRequestOperation { let resultBlock: FetchRequestOperationResultBlock var isCanceled = false var isFinished = false - private let feeds: [Feed] + private let fetchers: [ArticleFetcher] - init(id: Int, readFilterEnabledTable: [FeedIdentifier: Bool], feeds: [Feed], resultBlock: @escaping FetchRequestOperationResultBlock) { + init(id: Int, readFilterEnabledTable: [FeedIdentifier: Bool], fetchers: [ArticleFetcher], resultBlock: @escaping FetchRequestOperationResultBlock) { precondition(Thread.isMainThread) self.id = id self.readFilterEnabledTable = readFilterEnabledTable - self.feeds = feeds + self.fetchers = fetchers self.resultBlock = resultBlock } @@ -51,14 +51,14 @@ final class FetchRequestOperation { return } - if feeds.isEmpty { + if fetchers.isEmpty { isFinished = true resultBlock(Set
(), self) callCompletionIfNeeded() return } - let numberOfFetchers = feeds.count + let numberOfFetchers = fetchers.count var fetchersReturned = 0 var fetchedArticles = Set
() @@ -80,19 +80,19 @@ final class FetchRequestOperation { } } - for feed in feeds { - if feed.readFiltered(readFilterEnabledTable: readFilterEnabledTable) { - feed.fetchUnreadArticlesAsync { articleSetResult in - let articles = (try? articleSetResult.get()) ?? Set
() - process(articles) - } - } - else { - feed.fetchArticlesAsync { articleSetResult in + for fetcher in fetchers { + if (fetcher as? Feed)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true { + fetcher.fetchUnreadArticlesAsync { articleSetResult in + let articles = (try? articleSetResult.get()) ?? Set
() + process(articles) + } + } else { + fetcher.fetchArticlesAsync { articleSetResult in let articles = (try? articleSetResult.get()) ?? Set
() process(articles) } } + } } } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 0ad3a900d..7ff0db13e 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1906,8 +1906,8 @@ private extension SceneCoordinator { precondition(Thread.isMainThread) cancelPendingAsyncFetches() - let feeds = representedObjects.compactMap { $0 as? Feed } - let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, feeds: feeds) { [weak self] (articles, operation) in + let fetchers = representedObjects.compactMap { $0 as? ArticleFetcher } + let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, fetchers: fetchers) { [weak self] (articles, operation) in precondition(Thread.isMainThread) guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else { return