-
-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImportableUniqueObject take long time (on the first load) #502
Comments
That sounds about reasonable, since uniquing requires a fetch operation in addition to the write operations. Note that My suggestion would be to split the decoded extension Array {
func chunked(into size: Int) -> [[Element]] {
return stride(from: 0, to: count, by: size).map {
Array(self[$0 ..< Swift.min($0 + size, count)])
}
}
} ...
let movies = try decoder.decode([MovieJSON].self, from: data)
for chunk in movies.chunked(into: 100) { // adjust depending on how large each object import is
self.dataStack.perform(
asynchronous: { (transaction) -> Void in
try! transaction.importUniqueObjects(
Into<Movie>(),
sourceArray: chunk
)
},
completion: { (result) -> Void in
switch result {
case .success:
print("success")
// Merge your completion blocks somehow with something like a DispatchGroup
case .failure(let error):
print("error: \(error)")
}
}
)
}
... |
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 |
If you check the implementation of Let me know if you find an approach that works for your case so I can consider adopting it internally. |
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. |
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.
The text was updated successfully, but these errors were encountered: