From 34edd8a13faa94a5c8f8a3b7a3e24831e61a5217 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 3 Dec 2023 15:08:38 -0500 Subject: [PATCH] Fix reblogged statuses being pruned while still referenced, add workaround for crash --- .../Tusker.xcdatamodeld/Tusker.xcdatamodel/contents | 3 ++- Tusker/Scenes/MainSceneDelegate.swift | 2 +- Tusker/Screens/Timeline/TimelineViewController.swift | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Tusker/CoreData/Tusker.xcdatamodeld/Tusker.xcdatamodel/contents b/Tusker/CoreData/Tusker.xcdatamodeld/Tusker.xcdatamodel/contents index ba52345a..ae05395c 100644 --- a/Tusker/CoreData/Tusker.xcdatamodeld/Tusker.xcdatamodel/contents +++ b/Tusker/CoreData/Tusker.xcdatamodeld/Tusker.xcdatamodel/contents @@ -123,7 +123,8 @@ - + + diff --git a/Tusker/Scenes/MainSceneDelegate.swift b/Tusker/Scenes/MainSceneDelegate.swift index 3379ddc8..dcf37ae2 100644 --- a/Tusker/Scenes/MainSceneDelegate.swift +++ b/Tusker/Scenes/MainSceneDelegate.swift @@ -148,7 +148,7 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate minDate.addTimeInterval(-7 * 24 * 60 * 60) let statusReq: NSFetchRequest = StatusMO.fetchRequest() - statusReq.predicate = NSPredicate(format: "(lastFetchedAt = nil) OR (lastFetchedAt < %@)", minDate as NSDate) + statusReq.predicate = NSPredicate(format: "((lastFetchedAt = nil) OR (lastFetchedAt < %@)) AND (reblogs.@count = 0)", minDate as NSDate) let deleteStatusReq = NSBatchDeleteRequest(fetchRequest: statusReq) deleteStatusReq.resultType = .resultTypeCount if let res = try? context.execute(deleteStatusReq) as? NSBatchDeleteResult { diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 16d12fe7..a61095b4 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -445,6 +445,16 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro 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() + + // there was a bug where th the reblogged status would get pruned even when it was still refernced by the reblog + // as a temporary workaround, until there are no longer user db's in this state, + // check if the reblog is invalid and reload the status if so + if let reblog = status.reblog, + // force the fault to fire + case _ = reblog.id, + reblog.isDeleted { + unloaded.append(id) + } } else { unloaded.append(id) }