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
Attempt at fixing issue with getting next and previous push id #8817
Conversation
Please note that this is only marked as WIP since I would very much like feedback on the solution.
If you agree with the solution: Should I file issues for the other platforms that contain similar assumption errors in their successor and predecessor calculations with reference to this PR? Or will you take this up internally in some cross-platform firebase forum? :-) |
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 this! I think this is a reasonable solution.
It looks like some FIRDatabaseQueryTests
are failing in endBefore. Is that just in CI or do those tests fail locally as well?
Looks like style checks are failing
It's probably a good idea to add key validation. You can file issues pointing at this PR in the other platforms. This is a reasonable solution -- the internal firebase forum consensus is only needed for the API not the implementation. |
It appears that those tests are not being run through SwiftPM, that's the reason I've missed them. Not really certain about how to run them, but I'll go and have a look... |
@IanWyszynski , thank you very much for your review. I've implemented your suggestions - the only thing I haven't gotten around to yet is the tests that are not being executed using SwiftPM (which I use in my dev environment). I'll have a look at the latest test output from CI and see if I can find out what goes wrong by looking at that output. |
@IanWyszynski would you do a formal review of the PR, or would it be better if someone not involved closely with the details did that? |
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.
Please update https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseDatabase/CHANGELOG.md with a note for 8.10.0 with a summary of the fix.
Another small thought about this API: I am guessing that the API was added directly to the client since it does provide good value, and it seemed like an easy thing to add to the clients without involving the server. But as it turns out that it's not so easy, perhaps it would make sense for the server to provide the API out-of-the-box. Just my two cents - knowing absolutely nothing about the server side implementation and the difficulties of adding a new API there, so please take this as a very general comment. :-) |
As an addition to my comment above (that it might be better to implement the start after / start before queries server-side), I realized that the implementation in this PR might actually still not be accurate. If two keys are integer based, then the textually longest key comes after the shorter. I haven't tested how -00000 sorts compared to 000, but I would assume from the algorithm that -00000 comes after 000... Hmmm. This is a really hard thing to do right. @IanWyszynski @paulb777 |
Hmm, I just got the thought that there is actually an undefined sort order in the Obj-C and Javascript implementations of key sorting that I have seen. '-0' and '00' have the same length and the same numerical value, but they are not the same. What is their sort order? The RTDB console appears to be hiding my 00 key since there was already a -0 value... This looks like a bug, but I don't know how pervasive it is... Hmm, I guess internally 00 and -0 resolves to the same key internally... That's a bit confusing. Playing around in the console I get the following: I add a key "-0" with the value "minus zero" My conclusion is that "-0" and "00" resolve to the same key (as does "-00" and "000", etc.) |
Now you see it, now you don't:
Works in the simulator at least. |
I think I found a difference in the key sort between ios and js: In js there can be any number of 0's prefixed to a 32-bit int:
On iOS the length of the string is checked before conversion is attempted, so any string longer than 11 characters is never considered to be an integer value.
I haven't yet tested which of the two implementations the server appears to use. |
Now I've tested, and it appears that the javascript implementation matches the server implementation in this regard. Should I file an issue about this for the iOS implementation? Android appears to have the same issue:
|
Thanks @mortenbekditlevsen @IanWyszynski Would you follow up on the open questions and the review? |
@IanWyszynski @paulb777 |
Given the complexity of getting this right, I'm leaning towards moving startAfter/endBefore to the backend so we at least don't have to maintain a separate implementation in each SDK. @jsdt wdyt? |
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.
In email exchange with @IanWyszynski and @schmidt-sebastian, we agreed that even if a better long-term solution is a back end fix, this is a good interim solution.
@mortenbekditlevsen Anything outstanding to resolve before merging? I just tried the new test and the speed seems fine. It does look like the https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseDatabase/CHANGELOG.md still needs an update. |
It's still missing a fix for next/prev of an integer key prefixed by a number of zeroes. |
I'll look into fixing that part. |
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 this. Please let us know if you have time to address the feedback.
Ok, I have briefly considered the fix for 'integer' base key ordering. So here are some things to consider:
Does that sound about right? |
cc @jsdt and @IanWyszynski for comments on the ordering in |
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.
There is an outstanding conversation here, but I think we can go ahead and merge this since it fixes the immediate issue. I plan to re-implement startAfter/endBefore on the server side to avoid introducing this complexity in all the different SDKs, but I haven't been able to prioritize that work yet.
Thanks @IanWyszynski I resolved to unblock the merge and merged. |
Should I create an issue to track the discrepancy with key sorting on iOS and Android vs js and server? @paulb777 @IanWyszynski |
This is an attempt at fixing #8790. It's not very polished yet, and the test is currently too slow (loops over all single unicode character strings).