问题
I use Firebase database on my Android app. Normally, it works fine. But when the database is getting larger, the query performance is getting worse. I added about 5k record on database (under "elk" and "su" nodes), then I queried on database (on "cut" and "user" nodes) but all the queries are very very slow. I defined data index on database rules but it did not work. How can I solve that problem?
Here are my queries :
// query to get the zones followed by user
FirebaseDatabase.getInstance()
.getReference()
.child("user")
.child(userID)
.child("zones");
// query to get cuts on a zone
FirebaseDatabase.getInstance()
.getReference()
.child("cut")
.child(cutType)
.orderByChild("zoneID")
.equalTo(zoneID);
回答1:
If you want to continue expanding the best thing to do would be to duplicate your data in a zone reference where it knows which elk/su are a part of it. Something like this:
{
zones: {
elk: {
"istan-besik": {
"-KSp)bL5....": true,
...: true
}
}
}
}
That way when you want to search for all you would just do:
...child('zones').child(zoneId).child(cutType)
And then loop through those to go get each elk/su directly
来源:https://stackoverflow.com/questions/39768084/querying-on-firebase-database-with-large-data-set-is-very-very-slow