Made article search go fast

This commit is contained in:
Maurice Parker 2019-08-31 12:12:50 -05:00
parent 8002839941
commit 67b9721a10
1 changed files with 21 additions and 3 deletions

View File

@ -49,6 +49,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
private var expandedNodes = [Node]()
private var shadowTable = [[Node]]()
private var lastSearchString = ""
private var isSearching: Bool = false
private(set) var sortDirection = AppDefaults.timelineSortDirection {
didSet {
@ -105,14 +106,23 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
var timelineFetcher: ArticleFetcher? {
didSet {
currentArticleIndexPath = nil
if timelineFetcher is Feed {
showFeedNames = false
} else {
showFeedNames = true
}
fetchAndReplaceArticlesSync()
masterTimelineViewController?.reinitializeArticles()
if isSearching {
fetchAndReplaceArticlesAsync {
self.masterTimelineViewController?.reinitializeArticles()
}
} else {
fetchAndReplaceArticlesSync()
masterTimelineViewController?.reinitializeArticles()
}
}
}
@ -506,12 +516,20 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
func searchArticles(_ searchString: String) {
guard !searchString.isEmpty else {
isSearching = false
if let ip = currentMasterIndexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher {
timelineFetcher = fetcher
}
return
}
isSearching = true
if searchString.count < 3 {
timelineFetcher = nil
return
}
if searchString != lastSearchString {
timelineFetcher = SmartFeed(delegate: SearchFeedDelegate(searchString: searchString))
lastSearchString = searchString
@ -890,7 +908,7 @@ private extension AppCoordinator {
func emptyTheTimeline() {
if !articles.isEmpty {
articles = [Article]()
replaceArticles(with: Set<Article>(), animate: true)
}
}