Maybe fix race condition between iCloud sync and state restoration

This commit is contained in:
Shadowfacts 2023-01-17 10:50:36 -05:00
parent 5029b26b40
commit 68682ee291
1 changed files with 10 additions and 0 deletions

View File

@ -364,6 +364,8 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
] ]
SentrySDK.addBreadcrumb(crumb: crumb) SentrySDK.addBreadcrumb(crumb: crumb)
}() }()
let originalPositionStatusIDs = position.statusIDs
let unloaded = position.statusIDs.filter({ mastodonController.persistentContainer.status(for: $0) == nil }) let unloaded = position.statusIDs.filter({ mastodonController.persistentContainer.status(for: $0) == nil })
guard !unloaded.isEmpty else { guard !unloaded.isEmpty else {
return true return true
@ -420,6 +422,14 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
SentrySDK.addBreadcrumb(crumb: crumb) 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 // update the timeline position in case some statuses couldn't be loaded
if let center = position.centerStatusID { if let center = position.centerStatusID {
let nearestLoadedStatusToCenter = position.statusIDs[position.statusIDs.firstIndex(of: center)!...].first(where: { id in let nearestLoadedStatusToCenter = position.statusIDs[position.statusIDs.firstIndex(of: center)!...].first(where: { id in