Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance considerations on deleting Managed Objects using Cascade rule in Core Data
    primarykey
    data
    text
    <p>I searched within SO but I didn't find a any suggestions to boost performances on deleting Managed Object in Core Data when dealing with relationships.</p> <p>The scenario is quite simple.<img src="https://i.stack.imgur.com/WWeKP.png" alt="enter image description here"></p> <p>As you can see there are three different entities. Each entity is linked in cascade with the next. For example, <code>FirstLevel</code>has a relationship called <code>secondLevels</code> to <code>SecondLevel</code>. The delete rule from <code>FirstLevel</code> to <code>SecondLevel</code> is <strong>Cascade</strong> while the delete rule from <code>SecondLevel</code> to <code>FirstLevel</code> is <strong>Nullify</strong>. The same rules are applied between <code>SecondLevel</code> and <code>ThirdLevel</code>.</p> <p>When I want to delete the entire graph, I perform a method like the following:</p> <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"FirstLevel" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSError *error = nil; NSArray *items = [context executeFetchRequest:fetchRequest error:&amp;error]; [fetchRequest release]; // delete roots object and let Core Data to do the rest... for (NSManagedObject *managedObject in items) { [context deleteObject:managedObject]; } </code></pre> <p>Taking advantage of the <strong>Cascade</strong> rule the graph is removed. This works fast for few objects but decreases performances for many objects. In addition, I think (but I'm not very sure) that this type of deletion performs a lot of round trips to the disk, Am I wrong?</p> <p>So, my question is the following: how is it possible to remove the graph without taking advantage of <strong>Cascade</strong> rule and boost performances but, at the same time, maintain graph consistency?</p> <p>Thank you in advance.</p> <p><strong>EDIT</strong></p> <p>I cannot delete the entire file since I have other entities in my model.</p> <p><strong>EDIT 2</strong></p> <p>The code I posted is wrapped in the <code>main</code> method of a <code>NSOperation</code> subclass. This solution allows the deleting phase to be excuted in background. Since I took advantage of <strong>Cascade Rule</strong> the deletion is performed in a semi automatic way. I only delete root objects, the <code>FirstLevel</code> items, by means of the for loop within the posted code. In this way Core Data to do the rest for me. What I'm wondering is the following: is it possible to bybass that semi-automatic delete operation and do it manually without losing the graph consistency?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload