-
Notifications
You must be signed in to change notification settings - Fork 88
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
RDART-941: Clear collections in mixed when reassigned #1554
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder if it would be better to track what keys are not updated, and then remove only those, instead of removing all followed by setting them again.
I believe those to operations look quite different in the oplog.
Something similar holds for list, ie. only clear the elements in the old-list from length of the new-list and forward (if any), and update the rest.
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.
I guess it also depends on what operations are expected when you e.g. set a field to a new collection. In this case, it may be preferable/expected to have the items cleared, then set new ones, rather than removing some items and updating some items.
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.
It is definitely a choice, but it would avoid realm/realm-core#7422.
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.
I don't think we want to avoid that though (that issue) as it could make it easier for the SDKs, and the SDKs wouldn't have to call into Core for every item insert. It's definitely an interesting discussion to have, also for Core if we do delegate to them.
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.
Eventually the behavior should move to core, as to avoid the repeated calls. I'm more interested in what behavior we want.
Even if we go with clear, then assign, I think this should be handled by core, not the individual SDKs.
Also, to be consistent we should allow setting all collections, not just those in a mixed.
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.
Clearing the collection is the correct behavior here rather than replacing some of the elements because of the merge rules for CLEAR vs SET. Here's an example of when this could produce unwanted results:
If we didn't clear at point 3, the CLEAR instruction at point 2 would conflict with the SET instruction at point 3 and win over it, so we would lose the changes by Client 2, even though they were made at a later point. With the clear we're doing now, the point 2 CLEAR will be discarded and the SET-s in point 3 will be preserved.
Regarding setting non-mixed collections - the challenge there is that it breaks certain expectations compared to regular objects - e.g.:
So there is a strong expectation that what you set is what you get when working with properties. With collections, however, it wouldn't be the case, as we'd need to copy the collection contents over to Core, but wouldn't be able to manage it in-place. This is somewhat mitigated with collections in mixed due to the indirection that
Mixed/RealmValue
provides. When you pass in a list toRealmValue.from
, the API implies that you're initializing aRealmValue
with the contents of a collection and not just using the collection as is, so it's less clear whether users should expect this code to work: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.
Thanks for the clarification! Regarding the last example, for the SDKs having the
Mixed
wrapped (e.g. theRealmValue
class), I don't think the expectation necessarily is thatmyList.add(2);
also should be acting onmyPodo.mixed
due to the intermediate API that they'd have to go throughRealmValue.from()
.In this case, I'd say that a user's expectations may instead be based on what the API docs of
RealmValue.from()
says that it returns (e.g. the same reference asmyList
or something else (the latter in this case)).I think the ambiguity of what users would expect becomes more ambiguous for the JS SDK where the syntax is not differentiated as we don't wrap the
Mixed
value.