forked from shadowfacts/Tusker
Fix crash due to prematurely pruned statuses being fetched
If the app hasn't launched in long enough, we may be displaying old statuses as a result of state restoration. If the user leaves the app, those statuses can't get pruned, because the user may return. We need to make sure the lastFetchedAt date is current, since awakeFromFetch won't be called until the object is faulted in (which wasn't happening immediately during state restoration).
This commit is contained in:
parent
74820e8922
commit
bde21fbc6c
|
@ -59,9 +59,14 @@ public final class AccountMO: NSManagedObject, AccountProtocol {
|
||||||
super.awakeFromFetch()
|
super.awakeFromFetch()
|
||||||
|
|
||||||
managedObjectContext?.perform {
|
managedObjectContext?.perform {
|
||||||
self.lastFetchedAt = Date()
|
self.touch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the `lastFetchedAt` date so this object isn't pruned early.
|
||||||
|
func touch() {
|
||||||
|
lastFetchedAt = Date()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,15 @@ public final class StatusMO: NSManagedObject, StatusProtocol {
|
||||||
super.awakeFromFetch()
|
super.awakeFromFetch()
|
||||||
|
|
||||||
managedObjectContext?.perform {
|
managedObjectContext?.perform {
|
||||||
self.lastFetchedAt = Date()
|
self.touch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the `lastFetchedAt` date so this object isn't pruned early.
|
||||||
|
func touch() {
|
||||||
|
lastFetchedAt = Date()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension StatusMO {
|
extension StatusMO {
|
||||||
|
|
|
@ -440,7 +440,15 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
private func loadStatusesToRestore(position: TimelinePosition) async -> Bool {
|
private func loadStatusesToRestore(position: TimelinePosition) async -> Bool {
|
||||||
let originalPositionStatusIDs = position.statusIDs
|
let originalPositionStatusIDs = position.statusIDs
|
||||||
|
|
||||||
let unloaded = position.statusIDs.filter({ mastodonController.persistentContainer.status(for: $0) == nil })
|
var unloaded = [String]()
|
||||||
|
for id in position.statusIDs {
|
||||||
|
if let status = mastodonController.persistentContainer.status(for: id) {
|
||||||
|
// touch the status so that, even if it's old, it doesn't get pruned when we go into the background
|
||||||
|
status.touch()
|
||||||
|
} else {
|
||||||
|
unloaded.append(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
guard !unloaded.isEmpty else {
|
guard !unloaded.isEmpty else {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue