From 9b04b7594922fd750e33ab4d3b32b4725d10fd68 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 16 Aug 2020 10:29:31 -0400 Subject: [PATCH] Prevent potential race condition when loading additional statuses --- Tusker/Screens/Timeline/TimelineTableViewController.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineTableViewController.swift b/Tusker/Screens/Timeline/TimelineTableViewController.swift index fb39aed35e..e1f3117f4f 100644 --- a/Tusker/Screens/Timeline/TimelineTableViewController.swift +++ b/Tusker/Screens/Timeline/TimelineTableViewController.swift @@ -179,11 +179,12 @@ class TimelineTableViewController: EnhancedTableViewController { mastodonController.run(request) { response in guard case let .success(newStatuses, pagination) = response else { fatalError() } self.older = pagination?.older - let newRows = self.timelineSegments.last!.count..<(self.timelineSegments.last!.count + newStatuses.count) - let newIndexPaths = newRows.map { IndexPath(row: $0, section: self.timelineSegments.count - 1) } - self.timelineSegments[self.timelineSegments.count - 1].append(contentsOf: newStatuses.map { ($0.id, .unknown) }) self.mastodonController.persistentContainer.addAll(statuses: newStatuses) { DispatchQueue.main.async { + let newRows = self.timelineSegments.last!.count..<(self.timelineSegments.last!.count + newStatuses.count) + let newIndexPaths = newRows.map { IndexPath(row: $0, section: self.timelineSegments.count - 1) } + self.timelineSegments[self.timelineSegments.count - 1].append(contentsOf: newStatuses.map { ($0.id, .unknown) }) + UIView.performWithoutAnimation { self.tableView.insertRows(at: newIndexPaths, with: .none) }