Fix crash when displaying search results
This commit is contained in:
parent
0fa87e9177
commit
fb11e36467
|
@ -134,15 +134,19 @@ class SearchResultsViewController: EnhancedTableViewController {
|
||||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.performBatchUpdates({ (context, addAccounts, addStatuses) in
|
self.mastodonController.persistentContainer.performBatchUpdates({ (context, addAccounts, addStatuses) in
|
||||||
|
if oldSnapshot.indexOfSection(.accounts) != nil {
|
||||||
oldSnapshot.itemIdentifiers(inSection: .accounts).forEach { (item) in
|
oldSnapshot.itemIdentifiers(inSection: .accounts).forEach { (item) in
|
||||||
guard case let .account(id) = item else { return }
|
guard case let .account(id) = item else { return }
|
||||||
self.mastodonController.persistentContainer.account(for: id, in: context)?.decrementReferenceCount()
|
self.mastodonController.persistentContainer.account(for: id, in: context)?.decrementReferenceCount()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if oldSnapshot.indexOfSection(.statuses) != nil {
|
||||||
oldSnapshot.itemIdentifiers(inSection: .statuses).forEach { (item) in
|
oldSnapshot.itemIdentifiers(inSection: .statuses).forEach { (item) in
|
||||||
guard case let .status(id, _) = item else { return }
|
guard case let .status(id, _) = item else { return }
|
||||||
self.mastodonController.persistentContainer.status(for: id, in: context)?.decrementReferenceCount()
|
self.mastodonController.persistentContainer.status(for: id, in: context)?.decrementReferenceCount()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.onlySections.contains(.accounts) && !results.accounts.isEmpty {
|
if self.onlySections.contains(.accounts) && !results.accounts.isEmpty {
|
||||||
snapshot.appendSections([.accounts])
|
snapshot.appendSections([.accounts])
|
||||||
|
|
Loading…
Reference in New Issue