mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-12 04:10:36 +01:00
ImportableUniqueObject take long time (on the first load) #430
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @loicleser on GitHub (Apr 11, 2024).
Hello,
I'm testing your solution in my app. Everything looks really good and can be very helpful for me.
However, I'm encountering issues with the loading of the data. I'm trying to load a large set of movies from a JSON (40,000 movies). Everything works well with ImportableObject, but it duplicates the objects on each download. So, I implemented ImportableUniqueObject, and it takes a very long time to save the data.
With ImportableObject, it takes 1 or 2 seconds, and with ImportableUniqueObject, it takes 4 to 5 minutes.
Am I doing something wrong?
Here is my code:
Thank you for your help.
@JohnEstropia commented on GitHub (Apr 12, 2024):
That sounds about reasonable, since uniquing requires a fetch operation in addition to the write operations. Note that
importUniqueObjects()already optimizes this for you by doing only one fetch operation to map existing unique IDs before doing the write operations, but a large data is a large data. I suspect that the performance bottlenecks you're seeing is due to the high volume of memory use and disk IO being done in one whole transaction.My suggestion would be to split the decoded
moviesarray into batches. Something like this:@loicleser commented on GitHub (Apr 12, 2024):
Thank you for your response, I will conduct a test, but since I have other data to load, I don't think the solution will be sufficient. I need it to remain very fast. I will try to load the existing data in bulk and filter the new data before saving it to avoid using ImportableUniqueObject.
Thanks
@JohnEstropia commented on GitHub (Apr 12, 2024):
If you check the implementation of
importUniqueObjects(...), I think that's already what it does for you.Let me know if you find an approach that works for your case so I can consider adopting it internally.
@loicleser commented on GitHub (Apr 12, 2024):
Hello @JohnEstropia ,
I've started running some tests, but I've encountered an issue with the following code:
Even though I've set shouldUpdate and shouldInsert to return false, sources are still being inserted during didInsert. Is this behavior normal? I'd like to have precise control over when objects are added or updated.
Regarding my problem, I've come up with an initial, faster solution:
However, in some cases, I will need to update the names of some movies, so this solution doesn't completely resolve my problem.
Thank you for your assistance.