I am using Encrypted CoreData Sqlite Store to encrypt my CoreData stack. I have a table in database which stores more than 400k records. I want to delete most of those records based on some activity. As batch delete is not available for this encrypted store what I need to do is, execute a fetch request to read data.
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "MyEntity")
fetchRequest.includesPropertyValues = false
// Fetch data till minimum threshold limit
let newPredicate = NSPredicate(format: "%K <= %@", "recordTime", NSNumber(value: maxAllowedTimeStamp as Int64))
fetchRequest.predicate = newPredicate
let objectsToDelete = myDataController.executeFetchRequest(fetchRequest) as? [NSManagedObject]
Than I perform delete operation one-by-one the objects:
for object in objectsToDelete {
myDataController.deleteManagedObject(object)
}
This operation is taking more than 7-8 mins. I believe that core data is fast enough to provide fault object and it should not take this much time as you can see my predicate in which I am not taking any property value in order to reduce fetch time.
Can someone help me to understand what is taking so long to delete objects?