What is an efficient way to cascade deletes of objects from Core Data without sacrificing application performance?

The database in our application consists of objects nested in several layers. For architectural reasons, we cannot move from this right now.

A high percentage of data expires on a daily basis. Our application performance worsens as the database grows.

Therefore, we need to find an effective way to keep the database small (at least in this version), and we are considering one of the following approaches:

  • During applicationWillResignActive, delete NSManagedObjects, iterating through all objects at the root level, causing deletion at each of them, and then allowing cascading deletes for 3 layers of objects to many. This includes one context saving at the end that transfers all this to the database. Often, it takes 10-20 seconds to delete objects (on iPhone 4), and Springboard completes the process in 10 seconds. One of the main disadvantages of this is that if the persistence of the context does not complete before the 10-second timeout, nothing is deleted, and the database continues to grow every time the user launches the application.

  • Delete the entire sqlite file inside didFinishLaunchingWithOptions or applicationDidBecomeActive or inside the WillResignActive application. This forces us to go to the root of the application controller stack so as not to try to display deleted data. The biggest disadvantage of this is that the application must download and analyze the data for several seconds before the user can do anything the next time the application starts.

  • Delete the database objects using startBackgroundTaskWithExpirationHandler after the user clicks the Home or Power button. Unknown people are associated with this, which makes him scary. Does anyone do this (successfully) this way?

  • . , , . , API, , .

Core Data !

+5
3

orange80,

, -applicationDidEnterBackground:. , .

-. , , .

+1

, .

, ( ), ( ) . , , , , - , . , , .

, , - , , , , , " ". , ( ). , .

" " .

+1

, 1 . , , ( , ), (, ), "" " , , ( ). , , , , .

, , Core Data .

After quickly re-reading your question, I just thought ... On lines No. 2 ... why don't you experiment with transferring obsolete data to a separate file, and then when the user leaves the application, just delete this file? There will certainly be overhead for moving these objects, but it can provide a smoother UX.

0
source

All Articles