Remove prefetching

This commit is contained in:
Justin Mazzocchi 2021-01-16 15:39:42 -08:00
parent ca49611df5
commit 73fc2cd599
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C

View file

@ -42,7 +42,6 @@ class TableViewController: UITableViewController {
super.viewDidLoad() super.viewDidLoad()
tableView.dataSource = dataSource tableView.dataSource = dataSource
tableView.prefetchDataSource = self
tableView.cellLayoutMarginsFollowReadableWidth = true tableView.cellLayoutMarginsFollowReadableWidth = true
tableView.tableFooterView = UIView() tableView.tableFooterView = UIView()
tableView.contentInset.bottom = Self.bottomInset tableView.contentInset.bottom = Self.bottomInset
@ -98,7 +97,14 @@ class TableViewController: UITableViewController {
heightCache[item] = cell.frame.height heightCache[item] = cell.frame.height
cellHeightCaches[tableView.frame.width] = heightCache cellHeightCaches[tableView.frame.width] = heightCache
paginateIfLastIndexPathPresent(indexPaths: [indexPath]) if !loading,
indexPath.section == dataSource.numberOfSections(in: tableView) - 1,
indexPath.row == dataSource.tableView(tableView, numberOfRowsInSection: indexPath.section) - 1,
let maxId = viewModel.preferLastPresentIdOverNextPageMaxId
? dataSource.itemIdentifier(for: indexPath)?.itemId
: viewModel.nextPageMaxId {
viewModel.request(maxId: maxId, minId: nil)
}
} }
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
@ -124,12 +130,6 @@ class TableViewController: UITableViewController {
} }
} }
extension TableViewController: UITableViewDataSourcePrefetching {
func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
paginateIfLastIndexPathPresent(indexPaths: indexPaths)
}
}
extension TableViewController { extension TableViewController {
func report(reportViewModel: ReportViewModel) { func report(reportViewModel: ReportViewModel) {
let reportViewController = ReportViewController(viewModel: reportViewModel) let reportViewController = ReportViewController(viewModel: reportViewModel)
@ -451,18 +451,5 @@ private extension TableViewController {
present(activityViewController, animated: true, completion: nil) present(activityViewController, animated: true, completion: nil)
} }
func paginateIfLastIndexPathPresent(indexPaths: [IndexPath]) {
guard !loading,
let indexPath = indexPaths.last,
indexPath.section == dataSource.numberOfSections(in: tableView) - 1,
indexPath.row == dataSource.tableView(tableView, numberOfRowsInSection: indexPath.section) - 1,
let maxId = viewModel.preferLastPresentIdOverNextPageMaxId
? dataSource.itemIdentifier(for: indexPath)?.itemId
: viewModel.nextPageMaxId
else { return }
viewModel.request(maxId: maxId, minId: nil)
}
} }
// swiftlint:enable file_length // swiftlint:enable file_length