Querying on Firebase Database with large data set is very very slow

妖精的绣舞 提交于 2019-12-21 05:05:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!