mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
search performance improvements
This commit is contained in:
1 file changed
+5
-12
@@ -23,18 +23,15 @@ struct EmojiTableView: UIViewRepresentable {
|
|||||||
func updateUIView(_ uiView: UITableView, context: Context) {
|
func updateUIView(_ uiView: UITableView, context: Context) {
|
||||||
context.coordinator.hoarder = hoarder
|
context.coordinator.hoarder = hoarder
|
||||||
|
|
||||||
weak let dataSourceRef: UITableViewDiffableDataSource<Int, String>! = uiView.dataSource as? UITableViewDiffableDataSource<Int, String>
|
|
||||||
var snapshotBefore = dataSourceRef.snapshot()
|
|
||||||
let itemsBefore = context.coordinator.items
|
let itemsBefore = context.coordinator.items
|
||||||
let itemsAfter = items
|
let itemsAfter = items
|
||||||
context.coordinator.items = items
|
context.coordinator.items = items
|
||||||
Task.detached {
|
Task.detached {
|
||||||
guard !itemsAfter.isEmpty else {
|
guard !itemsAfter.isEmpty || itemsBefore.count-itemsAfter.count > 10_000 else {
|
||||||
snapshotBefore.deleteAllItems()
|
await context.coordinator.instantApplySnapshot()
|
||||||
dataSourceRef.apply(snapshotBefore, animatingDifferences: true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dataSourceRef.apply(context.coordinator.makeSnapshot(), animatingDifferences: true)
|
await context.coordinator.applySnapshot(animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,15 +66,11 @@ struct EmojiTableView: UIViewRepresentable {
|
|||||||
}
|
}
|
||||||
func applySnapshot(animated: Bool) async {
|
func applySnapshot(animated: Bool) async {
|
||||||
let snapshot = makeSnapshot()
|
let snapshot = makeSnapshot()
|
||||||
(self.tableView.dataSource as! UITableViewDiffableDataSource).apply(snapshot, animatingDifferences: animated) {
|
await (self.tableView.dataSource as! UITableViewDiffableDataSource).apply(snapshot, animatingDifferences: animated)
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
func instantApplySnapshot() async {
|
func instantApplySnapshot() async {
|
||||||
let snapshot = makeSnapshot()
|
let snapshot = makeSnapshot()
|
||||||
(self.tableView.dataSource as! UITableViewDiffableDataSource).applySnapshotUsingReloadData(snapshot) {
|
await (self.tableView.dataSource as! UITableViewDiffableDataSource).applySnapshotUsingReloadData(snapshot)
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cell(
|
func cell(
|
||||||
|
|||||||