Delete improvement when clearing the database #384

Open
opened 2025-12-29 15:30:36 +01:00 by adam · 1 comment
Owner

Originally created by @alinpetrus on GitHub (Mar 8, 2022).

We are using CoreStore and while we love it, there is one thing that is causing us a bit of trouble. When wanting to clear the whole database, we need to go through all the entities and do calls to deleteAll for each entity.
For large datasets this is fairly time consuming.

I am wondering if we could have something which is faster like using NSBatchDeleteRequest or a call to destroyPersistentStore on each store and recreating them afterwards.

Originally created by @alinpetrus on GitHub (Mar 8, 2022). We are using CoreStore and while we love it, there is one thing that is causing us a bit of trouble. When wanting to clear the whole database, we need to go through all the entities and do calls to deleteAll for each entity. For large datasets this is fairly time consuming. I am wondering if we could have something which is faster like using NSBatchDeleteRequest or a call to destroyPersistentStore on each store and recreating them afterwards.
adam added the enhancement label 2025-12-29 15:30:36 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Mar 9, 2022):

@alinpetrus Thanks. Should be simple enough to expose a safe method for it (since cs_eraseStorageAndWait() already exists for the purpose of migrations). The hard part is ensuring that the existing observers are notified of the deletions. I'll try to push a prototype into develop this weekend and let you play with it before we merge it to main.

In the mean time, if you can ensure that all references to the DataStack can be initialized, you can just replace your DataStack with a new one, delete the files related to the old SQLiteStore().fileURL, and re-add the SQLiteStore to the new DataStack. I have two projects that does this safely, but yeah we should have a supported safe way to remove stores in the API.

@JohnEstropia commented on GitHub (Mar 9, 2022): @alinpetrus Thanks. Should be simple enough to expose a safe method for it (since `cs_eraseStorageAndWait()` already exists for the purpose of migrations). The hard part is ensuring that the existing observers are notified of the deletions. I'll try to push a prototype into `develop` this weekend and let you play with it before we merge it to `main`. In the mean time, if you can ensure that all references to the `DataStack` can be initialized, you can just replace your `DataStack` with a new one, delete the files related to the old `SQLiteStore().fileURL`, and re-add the `SQLiteStore` to the new `DataStack`. I have two projects that does this safely, but yeah we should have a supported safe way to remove stores in the API.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#384