From 68682ee2911f04d159aa2719850350c1812d20dd Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 17 Jan 2023 10:50:36 -0500 Subject: [PATCH] Maybe fix race condition between iCloud sync and state restoration --- Tusker/Screens/Timeline/TimelineViewController.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index bf6b03ed..aa14aaa9 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -364,6 +364,8 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro ] SentrySDK.addBreadcrumb(crumb: crumb) }() + let originalPositionStatusIDs = position.statusIDs + let unloaded = position.statusIDs.filter({ mastodonController.persistentContainer.status(for: $0) == nil }) guard !unloaded.isEmpty else { return true @@ -420,6 +422,14 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro SentrySDK.addBreadcrumb(crumb: crumb) }() + // if an icloud sync completed in between starting to load the statuses and finishing, try to load again + if position.statusIDs != originalPositionStatusIDs { + let crumb = Breadcrumb(level: .info, category: "TimelineViewController") + crumb.message = "TimelinePosition statusIDs changed, retrying load" + SentrySDK.addBreadcrumb(crumb: crumb) + return await loadStatusesToRestore(position: position) + } + // update the timeline position in case some statuses couldn't be loaded if let center = position.centerStatusID { let nearestLoadedStatusToCenter = position.statusIDs[position.statusIDs.firstIndex(of: center)!...].first(where: { id in