Change to utilize ArticleFetchers instead of Feeds so that the single article fetcher stops getting filtered out. Issue #2416

This commit is contained in:
Maurice Parker 2020-09-12 18:09:42 -05:00
parent feba4a7bc6
commit c580877a86
3 changed files with 24 additions and 24 deletions

View File

@ -1129,19 +1129,19 @@ private extension TimelineViewController {
func fetchUnsortedArticlesSync(for representedObjects: [Any]) -> Set<Article> { func fetchUnsortedArticlesSync(for representedObjects: [Any]) -> Set<Article> {
cancelPendingAsyncFetches() cancelPendingAsyncFetches()
let feeds = representedObjects.compactMap{ $0 as? Feed } let fetchers = representedObjects.compactMap{ $0 as? ArticleFetcher }
if feeds.isEmpty { if fetchers.isEmpty {
return Set<Article>() return Set<Article>()
} }
var fetchedArticles = Set<Article>() var fetchedArticles = Set<Article>()
for feed in feeds { for fetchers in fetchers {
if feed.readFiltered(readFilterEnabledTable: readFilterEnabledTable) { if (fetchers as? Feed)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true {
if let articles = try? feed.fetchUnreadArticles() { if let articles = try? fetchers.fetchUnreadArticles() {
fetchedArticles.formUnion(articles) fetchedArticles.formUnion(articles)
} }
} else { } else {
if let articles = try? feed.fetchArticles() { if let articles = try? fetchers.fetchArticles() {
fetchedArticles.formUnion(articles) fetchedArticles.formUnion(articles)
} }
} }
@ -1154,8 +1154,8 @@ private extension TimelineViewController {
// if its been superseded by a newer fetch, or the timeline was emptied, etc., it wont get called. // if its been superseded by a newer fetch, or the timeline was emptied, etc., it wont get called.
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
cancelPendingAsyncFetches() cancelPendingAsyncFetches()
let feeds = representedObjects.compactMap { $0 as? Feed } let fetchers = representedObjects.compactMap { $0 as? ArticleFetcher }
let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, feeds: feeds) { [weak self] (articles, operation) in let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, fetchers: fetchers) { [weak self] (articles, operation) in
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else { guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else {
return return

View File

@ -23,13 +23,13 @@ final class FetchRequestOperation {
let resultBlock: FetchRequestOperationResultBlock let resultBlock: FetchRequestOperationResultBlock
var isCanceled = false var isCanceled = false
var isFinished = 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) precondition(Thread.isMainThread)
self.id = id self.id = id
self.readFilterEnabledTable = readFilterEnabledTable self.readFilterEnabledTable = readFilterEnabledTable
self.feeds = feeds self.fetchers = fetchers
self.resultBlock = resultBlock self.resultBlock = resultBlock
} }
@ -51,14 +51,14 @@ final class FetchRequestOperation {
return return
} }
if feeds.isEmpty { if fetchers.isEmpty {
isFinished = true isFinished = true
resultBlock(Set<Article>(), self) resultBlock(Set<Article>(), self)
callCompletionIfNeeded() callCompletionIfNeeded()
return return
} }
let numberOfFetchers = feeds.count let numberOfFetchers = fetchers.count
var fetchersReturned = 0 var fetchersReturned = 0
var fetchedArticles = Set<Article>() var fetchedArticles = Set<Article>()
@ -80,19 +80,19 @@ final class FetchRequestOperation {
} }
} }
for feed in feeds { for fetcher in fetchers {
if feed.readFiltered(readFilterEnabledTable: readFilterEnabledTable) { if (fetcher as? Feed)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true {
feed.fetchUnreadArticlesAsync { articleSetResult in fetcher.fetchUnreadArticlesAsync { articleSetResult in
let articles = (try? articleSetResult.get()) ?? Set<Article>() let articles = (try? articleSetResult.get()) ?? Set<Article>()
process(articles) process(articles)
} }
} } else {
else { fetcher.fetchArticlesAsync { articleSetResult in
feed.fetchArticlesAsync { articleSetResult in
let articles = (try? articleSetResult.get()) ?? Set<Article>() let articles = (try? articleSetResult.get()) ?? Set<Article>()
process(articles) process(articles)
} }
} }
} }
} }
} }

View File

@ -1906,8 +1906,8 @@ private extension SceneCoordinator {
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
cancelPendingAsyncFetches() cancelPendingAsyncFetches()
let feeds = representedObjects.compactMap { $0 as? Feed } let fetchers = representedObjects.compactMap { $0 as? ArticleFetcher }
let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, feeds: feeds) { [weak self] (articles, operation) in let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, fetchers: fetchers) { [weak self] (articles, operation) in
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else { guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else {
return return