mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
ListMonitor strange behaviour #305
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 27, 2020).
Hi!
Trying to use ListMonitor for triggering attachments delete from db to delete blobs locally:
But object.local_ref is nil in func listMonitor(_ monitor: ListMonitor, didDeleteObject object: ListEntityType, fromIndexPath indexPath: IndexPath)
If I add
object.local_re_ is NOT nil in func listMonitor(_ monitor: ListMonitor, didDeleteObject object: ListEntityType, fromIndexPath indexPath: IndexPath_ and everything works as expected
Has anyone encountered this behaviour?
Thanks
@JohnEstropia commented on GitHub (Jan 28, 2020):
@spacedema Which base are you using,
NSManageObjectorCoreStoreObject?@spacedema commented on GitHub (Jan 28, 2020):
@JohnEstropia nsmanagedobject
@JohnEstropia commented on GitHub (Jan 28, 2020):
Ah,
didDeleteObjectis too late to access any values. At this point the cache dictionary is destroyed (all the properties will benil,0, or""depending on the type). The only valid value you can reliably use here isobjectID.@spacedema commented on GitHub (Jan 28, 2020):
But values not nil in didDeleteObject if I implement listMonitorWillChange as I wrote above.
@JohnEstropia, can you suggest me the right way to solve my task?
@JohnEstropia commented on GitHub (Jan 28, 2020):
That's because your
log.debug()accesses all thelocal_ref, which fires the faults for all objects and caches them in memory. Otherwise theListMonitorneeds to query the database, which would not contain the value anymore since it was just deleted.You'll need to manage your own cache that is guaranteed to not rely on Core Data's fault. Something like
In any case, you might want to run a regular cleanup anyway because
removeItemmay fail if that file's handle is still held by any process in the device. If you'll do that you'll need to query all savedlocal_refs, iterate all files in your blob folder, and delete all files not in thelocal_refs list. Of course this assumes you don't have other unrelated files mixed into that folder.@spacedema commented on GitHub (Jan 28, 2020):
Thanks for your help, @JohnEstropia !