I use NSTreeController
+ NSOutlineView
to display a large tree (with over 1K nodes). The tree is constructed with an adjacency list. In NSTreeController
is turned on a LazyFetching. When I try to remove a node NSTreeController
starts to fulfill all fault descendant nodes.
It produces a delay if a tree is large.
The fulfill log is the following:
2015-03-10 17:10:22.945 TreeTest[1909:303] CoreData: sql: SELECT 0, t0.Z_PK FROM ZENTITY t0 WHERE t0.ZPARENT = ?
2015-03-10 17:10:22.946 TreeTest[1909:303] CoreData: annotation: sql connection fetch time: 0.0007s
2015-03-10 17:10:22.947 TreeTest[1909:303] CoreData: annotation: total fetch execution time: 0.0012s for 0 rows.
2015-03-10 17:10:22.947 TreeTest[1909:303] CoreData: annotation: to-many relationship fault "children" for objectID 0x100568450 <x-coredata://5DB6B2D8-646B-4D2B-ACEA-86E91B6523FB/Entity/p3390> fulfilled from database. Got 0 rows
Is it a normal behavior ? How can I prevent it ?
Actually it is not a problem of NSTreeController
. It is how Core Data
works when a NSManagedObject
is being deleted. If you have in your entity relations with delete rule eq 'cascade' it loads all related objects (or fulfills fault objects) for such entity and then deletes them one by one.
So if you use 'cascade' rule and sqlite backend, Core Data
applies 'cascade' rule by itself and does not relay on backend.