Start work on performance optimization for the timeline view — make looking up a row for an Article faster.
This commit is contained in:
parent
33fe733a8e
commit
9ad468781d
|
@ -30,12 +30,14 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
|
||||||
if articles != oldValue {
|
if articles != oldValue {
|
||||||
dataSource.articles = articles
|
dataSource.articles = articles
|
||||||
updateShowAvatars()
|
updateShowAvatars()
|
||||||
|
articleRowMap = [String: Int]()
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var undoableCommands = [UndoableCommand]()
|
var undoableCommands = [UndoableCommand]()
|
||||||
|
private var articleRowMap = [String: Int]() // articleID: rowIndex
|
||||||
private var cellAppearance: TimelineCellAppearance!
|
private var cellAppearance: TimelineCellAppearance!
|
||||||
private var cellAppearanceWithAvatar: TimelineCellAppearance!
|
private var cellAppearanceWithAvatar: TimelineCellAppearance!
|
||||||
private var showFeedNames = false {
|
private var showFeedNames = false {
|
||||||
|
@ -696,6 +698,47 @@ private extension TimelineViewController {
|
||||||
restoreSelection(savedSelection)
|
restoreSelection(savedSelection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func row(for articleID: String) -> Int? {
|
||||||
|
updateArticleRowMapIfNeeded()
|
||||||
|
return articleRowMap[articleID]
|
||||||
|
}
|
||||||
|
|
||||||
|
func row(for article: Article) -> Int? {
|
||||||
|
return row(for: article.articleID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateArticleRowMap() {
|
||||||
|
var rowMap = [String: Int]()
|
||||||
|
var index = 0
|
||||||
|
articles.forEach { (article) in
|
||||||
|
rowMap[article.articleID] = index
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
articleRowMap = rowMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateArticleRowMapIfNeeded() {
|
||||||
|
if articleRowMap.isEmpty {
|
||||||
|
updateArticleRowMap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func indexesForArticleIDs(_ articleIDs: Set<String>) -> IndexSet {
|
||||||
|
|
||||||
|
var indexes = IndexSet()
|
||||||
|
|
||||||
|
articleIDs.forEach { (articleID) in
|
||||||
|
guard let oneIndex = row(for: articleID) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if oneIndex != NSNotFound {
|
||||||
|
indexes.insert(oneIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexes
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Fetching Articles
|
// MARK: Fetching Articles
|
||||||
|
|
||||||
func fetchArticles() {
|
func fetchArticles() {
|
||||||
|
|
Loading…
Reference in New Issue