I am using react-native-firebase 1.1.0
if (key > expectedKey) {
for (long i = expectedKey; i < key; i++) {
array.pushNull();
}
expectedKey = key;
}
But, since long key = Long.parseLong(child.getKey());
and my key is 15 digits++ long. This block is practically cannot be done.
I thinks it's not enough to check isArray with only Long.parseLong() and loop through index like this in https://github.com/invertase/react-native-firebase/blob/master/android/src/main/java/io/invertase/firebase/Utils.java#L218 and https://github.com/invertase/react-native-firebase/blob/master/android/src/main/java/io/invertase/firebase/Utils.java#L240
I thinks you should remove convert to array entirely http://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html return data as is and let people handle data in javascript instead of low level like this which is this process is prone to error
1) data is sparse array
2) data is not array but key is integer (in our case is facebook id which data auto generate by firebase.auth (profile_facebook))
Someone mentioned this hang before but we couldn't find the source, but now we know 馃憤
However, the firebase web sdk and ios sdk do this automatically for you and the android one does not - which is why we added this functionality - to keep them all in the same format and to pass consistency tests this conversion needs to remain in the library - so it needs fixing rather than removing 馃檲
Could you run the same query on the web sdk or ios sdk and let me know the results - do the official ones hang on this? Whats the format they return - object or array?
cc @chrisbianca
my query is
firebase.database().ref('profile_facebook')
.orderByChild('uid')
.equalTo('sampleuserid')
.once('value', data => {
console.log(data.key))
console.log(data.val()))
})
=> 101539255xxx39749
=> {
email: "[email protected]"
name: "My Name"
profile_picture: "https://scontent.xx.fbcdn.net/v/t1.0-1/..."
uid: "sampleuserid"
}
@guhungry is a dev in the same team.
@Salakar I have already tested the given data on official SDK for Android, iOS and Web. They all are working fine. Both Array and Object.
Now, my node structure is using Facebook user id, which is number, as a key. So, Utils.castValue()
sees and treats it as an Array.
The result DataSnapshot
from Query.once('value').then(function(snapshot){})
is also, turned in to Zero-indexed Array. But all the keys are kept in childKeys
anyway. Which mean that, keys assigned to _value
and keys assigned to childKeys
are inconsistent.
@SekRanger Just so I understand clearly, are you able to paste a snippet of the data that you have in the Realtime Database which is causing the problem? The code above is useful, but having the data means we can create a test.
I think I have a way of fixing this but want to confirm it does work as I expect.
Here is the snippet of the data. The code we are using is already stated by @guhungry.
"profile_facebook": {
"10053768200609241" : {
"email" : "[email protected]",
"name" : "Sek Ranger",
"profile_picture" : "https://url.to/picture",
"uid" : "n6V8vACidyW4OKxnELkBbW83JaS2"
},
"10053925505239749" : {
"email" : "[email protected]",
"name" : "Gu Hungry",
"profile_picture" : "https://url.to/picture",
"uid" : "Qq4Pwm7H2kO6sJIMLAJxuhAGGh22"
},
"10106631429240929" : {
"email" : "[email protected]",
"name" : "Chwang",
"profile_picture" : "https://url.to/picture",
"uid" : "T7VVrveS0dPs3idmgetLUfQsLZs1"
},
"200630112702946" : {
"email" : "[email protected]",
"name" : "Introv Bigs",
"profile_picture" : "https://url.to/picture",
"uid" : "aNYxLexOb2WsXGOPiEAu47q5bxH3"
}
}
This has been fixed on the v2 branch: https://github.com/invertase/react-native-firebase/commit/2fdb73656eac045084a9b9caa5160f843839774c
What can I do with the current version?
@SekRanger Let me back port onto the current branch and release a new version
v1.1.1 is now live: https://github.com/invertase/react-native-firebase/releases/tag/v1.1.1
Please let me know if you're still experiencing issues after updating
@chrisbianca confirm fixed. Thank you so much.
@chrisbianca Thank you so much. This is a major performance improvement for the app we are working on.
@guhungry @SekRanger you're welcome, glad it's resolved!
Most helpful comment
This has been fixed on the v2 branch: https://github.com/invertase/react-native-firebase/commit/2fdb73656eac045084a9b9caa5160f843839774c