mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-12 04:10:36 +01:00
List Monitor and Cascade Delete #382
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @spacedema on GitHub (Jan 21, 2022).
I have two entities with 1->M relationship. Note and Attachment (note can have many attachments and the attachment holds link to the note).


I'm using
NSManageObjectand I have AttachmentsDbListenerSteps to reproduce the issue:
listMonitorWillChangeAll fields are nil, so I can't delete local attachments blobs
@JohnEstropia commented on GitHub (Jan 24, 2022):
@spacedema This seems to be the expected behavior if the objects you access in
listMonitorWillChangeare in faulted state. At that state, accessing the object (firing its fault) would attempt to fetch values from the persistent store, where it obviously had already been deleted.When objects had been deleted, consider those objects as tombstones and the only reliable info would be its
NSManagedObjectID.Looking at your use case, I would suggest to keep a cache of
object.localPaths and use theNSManagedObjectIDas keys. You can then execute your cleanup code anytime later on using the deleted object'sobjectID.@spacedema commented on GitHub (Jan 24, 2022):
It looks too complicated. It would be easier if Persistent History Tracking were implemented (https://developer.apple.com/documentation/coredata/consuming_relevant_store_changes).
Preserve after deletionwould solve this problem, wouldn't it?@JohnEstropia commented on GitHub (Jan 24, 2022):
@spacedema I don't think the
Preserve after deletionfeature works how you imagine it would. Yes, the attribute value will be saved even for deleted records, but that data belongs to theNSPersistentHistoryTransaction. It will not be propagated toNSManagedObjectinstances. History transaction records are only used to notifyNSManagedObjectContextsof external changes, but faulted objects still fetch data from the store.Even when Core Store eventually implements Persistent History Tracking, I don't intend to open up an API to access the raw history transactions as shown in the sample codes. That's for merging diffs into the relevant contexts. Of course you're free to observe relevant
NSNotifications at that point, but I doubt it would be less complicated that just managing cleanup tables on your own:@spacedema commented on GitHub (Jan 24, 2022):
Ok, got it, thanks for detailed answer.
But I'll still wait for the implementation of Persistent History Tracking in order to use Spotlight with NSCoreDataCoreSpotlightDelegate :)
@spacedema commented on GitHub (Jan 24, 2022):
@JohnEstropia the code above don't work as expected after reopen app, i.e.
listMonitorDidChangeandlistMonitorDidRefetchnot called,localPathsByIDis EmptyBut if i wrote
it's working as expected. Is it expected behaviour?
@JohnEstropia commented on GitHub (Jan 24, 2022):
Yes, you'd want to get the latest values right after you call
addObserver(). My code was just pseudo code 👍@spacedema commented on GitHub (Jan 24, 2022):
Got it, thanks