[go: nahoru, domu]

Skip to content
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

Workaround for NSDecimalNumber longLongValue issue. #4109

Merged

Conversation

mortenbekditlevsen
Copy link
Contributor
@mortenbekditlevsen mortenbekditlevsen commented Oct 17, 2019

Discussion

The discussion of the issue can be found here:
#4108

This PR only provides a workaround for a bug with [NSDecimalNumber longLongValue] on values with high precision.

It does not deal with the fact that the RTDB server appears to store a double wrapped in an NSNumber differently than the same value wrapped in an NSDecimalNumber.
As an NSDecimalNumber the higher precision is stored, but the persistence layer has no knowledge about whether we are in one case or the other.

Testing

The added logic changes the CFNumber type of one of the existing tests. Otherwise all existing tests passed.

API Changes

No API changes in the PR.

@mortenbekditlevsen mortenbekditlevsen changed the title Workaround for NSDecimalNumber longLongValue issue. WIP: Workaround for NSDecimalNumber longLongValue issue. Oct 17, 2019
…th [NSDecimalNumber longLongValue]. Still does not deal with the fact that a double and an NSDecimalNumber wrapping a double can be represented in different ways on the server.
@mortenbekditlevsen mortenbekditlevsen changed the title WIP: Workaround for NSDecimalNumber longLongValue issue. Workaround for NSDecimalNumber longLongValue issue. Oct 17, 2019
@paulb777
Copy link
Member

@mortenbekditlevsen Thanks for the PR! It looks like our new Danger integration is breaking CI for external PRs. cc: @morganchen12 We'll investigate that and get this reviewed.

@morganchen12
Copy link
Contributor

@mortenbekditlevsen The danger issue has been fixed in master, if you merge/rebase it should go away. Sorry for the inconvenience!

Copy link
Contributor
@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this! I have some comment/naming nits but otherwise this is fine.

@@ -878,7 +878,17 @@ - (id)fixDoubleParsing:(id)value
// values, including 2.47. Because we use the exact bytes for hashing on the
// server this will lead to hash mismatches. The parser of NSNumber seems to
// be more in line with what the server expects, so we use that here
if ([value isKindOfClass:[NSNumber class]]) {
if ([value isKindOfClass:[NSDecimalNumber class]]) {
NSDecimal d = [(NSDecimalNumber*)value decimalValue];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of renaming "d" to "original" and "result" to "rounded"?

@@ -878,7 +878,17 @@ - (id)fixDoubleParsing:(id)value
// values, including 2.47. Because we use the exact bytes for hashing on the
// server this will lead to hash mismatches. The parser of NSNumber seems to
// be more in line with what the server expects, so we use that here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this existing comment into the else if if ([value isKindOfClass:[NSNumber class]]) block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly, but the essential idea of what is going on inside both the NSDecimalNumber case and the NSNumber case is the same, so does this comment not apply to both?

I am updating the PR with the moved comment, but I think that perhaps it belongs to the entire method.

@@ -878,7 +878,17 @@ - (id)fixDoubleParsing:(id)value
// values, including 2.47. Because we use the exact bytes for hashing on the
// server this will lead to hash mismatches. The parser of NSNumber seems to
// be more in line with what the server expects, so we use that here
if ([value isKindOfClass:[NSNumber class]]) {
if ([value isKindOfClass:[NSDecimalNumber class]]) {
NSDecimal d = [(NSDecimalNumber*)value decimalValue];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment with a link to the underlying Radar here.

@mortenbekditlevsen
Copy link
Contributor Author

Thank you very much for the review. I have updated the PR with requested changes and added additional comments.

Have you had a chance to consider the other issue described in: #4108?
Namely that it appears that the RTDB server can represent the 'same' value in different versions based on whether it is wrapped as an NSDecimalNumber or not.
This is all fine and good, but it seems that the persistence layer can not know which representation is desired, and this could cause hashing/sync issues - and also minor precision issues based on whether you are enabling persistence or not.

Copy link
Contributor
@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the PR. Your comments are extremely helpful and I would like to merge this as is.

If you see excessive network traffic even with this fix due to hash mismatches, then let's go back and see if there are other fixes we need to make. I am bit afraid that this might lead us to a slippery slope, where in the end we have to do so much post-processing that we are essentially implementing our own JSON number parser. Fortunately, we do compute our Node hashes based on deserialized data, so we should already have the same hash value (at least when the backend and the SDK agree on the long representation).

@schmidt-sebastian schmidt-sebastian merged commit 0a04968 into firebase:master Oct 18, 2019
@firebase firebase locked and limited conversation to collaborators Nov 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants