Skip reloadData in TimelineViewController when the articles array represents the same articles as the previous array. Just reload visible cells in that case.
This commit is contained in:
parent
58012a97f3
commit
4d3bceda93
|
@ -102,5 +102,20 @@ extension Array where Element == Article {
|
|||
let articles = self.filter{ !$0.status.read }
|
||||
return articles.isEmpty ? nil : articles
|
||||
}
|
||||
|
||||
func representSameArticlesInSameOrder(as otherArticles: [Article]) -> Bool {
|
||||
if self.count != otherArticles.count {
|
||||
return false
|
||||
}
|
||||
var i = 0
|
||||
for article in self {
|
||||
let otherArticle = otherArticles[i]
|
||||
if article.account != otherArticle.account || article.articleID != otherArticle.articleID {
|
||||
return false
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,13 +28,22 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
|
|||
|
||||
var articles = ArticleArray() {
|
||||
didSet {
|
||||
if articles != oldValue {
|
||||
if articles == oldValue {
|
||||
return
|
||||
}
|
||||
if articles.representSameArticlesInSameOrder(as: oldValue) {
|
||||
// When the array is the same — same articles, same order —
|
||||
// but some data in some of the articles may have changed.
|
||||
// Just reload visible cells in this case: don’t call reloadData.
|
||||
articleRowMap = [String: Int]()
|
||||
reloadVisibleCells()
|
||||
return
|
||||
}
|
||||
updateShowAvatars()
|
||||
articleRowMap = [String: Int]()
|
||||
tableView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var undoableCommands = [UndoableCommand]()
|
||||
private var articleRowMap = [String: Int]() // articleID: rowIndex
|
||||
|
@ -441,6 +450,13 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
|
|||
return nil
|
||||
}
|
||||
|
||||
private func reloadVisibleCells() {
|
||||
guard let indexes = tableView.indexesOfAvailableRows() else {
|
||||
return
|
||||
}
|
||||
reloadVisibleCells(for: indexes)
|
||||
}
|
||||
|
||||
private func reloadVisibleCells(for articles: [Article]) {
|
||||
reloadVisibleCells(for: Set(articles.articleIDs()))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue