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
Adds Realm.copyFromRealm() #1849
Conversation
@realm/java |
Interesting! How does maxDepth work here? |
@@ -31,8 +31,11 @@ | |||
import javax.lang.model.element.VariableElement; | |||
import javax.lang.model.type.DeclaredType; | |||
import javax.lang.model.util.Types; | |||
import javax.rmi.CORBA.Util; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this import
seems to be unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, will fix
It is there to prevent copying to much data. Realm is an Object database so you might construct your data model in such a way that you can access the entire graph. This could be potentially very memory intensive to copy, so being able to break the graph makes this scenario easier to control so you don't run out of memory. See e.g this unit test: https://github.com/realm/realm-java/pull/1849/files#diff-b11f4583c757aa2c5f52d4fb9e4ac750R2348 |
Looks good. Thank you! I've been cloning into raw-objects manually in my code. |
Current implementation searches and duplicates the object graph by depth-first search. To avoid this reconstruction, we can use the breadth-first search since the depth monotonically increases. This is just an optimization and might not be needed at first release. |
Yes, it is depth first currently. Mostly because it was easier to implement and also because I think this feature will mostly be used on leaf nodes, which means we won't have to repopulate objects often (pure speculation though). So as far as I can see we have the following trade-offs: Breath-first
Depth-first:
Given that I wouldn't anticipate this being used on either many or deep objects i opted for simplicity, but I'm happy to hear arguments for changing it? |
@@ -1,3 +1,6 @@ | |||
0.87.0 | |||
* Added Realm.copyFromRealm() for creating detached copies of Realm data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"data" -> "objects"
Nice! 👍 |
Depth-first is OK as first release. We should keep simple if possible. 👍 |
Even though I do have reservations about diverging from the zero-copy principle I think it looks good. |
01d30e2
to
f028bf9
Compare
Is it possible to start using 0.87 so that I can use this feature? |
Yes, you can use our SNAPSHOT releases : https://github.com/realm/realm-java#using-snapshots |
Ah yes, thanks! |
I wonder why this functionality maintained only in Java. Just run into the situation where it would be nice to have it in Swift. |
The Android and Swift communities have different paradigms, patterns and libraries that are commonly used. So while we strive to have feature parity between Java / Swift / Objective-C there will always be small differences. If it is a feature you would like implemented I would suggest raising it as an issue for Realm Swift. They already have an issue tracking it here: realm/realm-swift#3381 |
Thanks, I think I will find a simple workaround this time. |
thanks @cmelchior, nice job |
Awesome!!!! thank you for this! |
Fixes #931
Adds 4 new methods that makes it possible to make detached deep copies of managed RealmObjects:
As discussed this breaks Realms zero-copy and consistency guarantees, but enables architectural patterns currently not supported by Realm.