在具有大型数据集的Firebase数据库上查询非常慢 [英] Querying on Firebase Database with large data set is very very slow

查看:71
本文介绍了在具有大型数据集的Firebase数据库上查询非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用上使用Firebase数据库。通常,它工作正常。但是,当数据库变大时,查询性能会变差。我在数据库(在 elk和 su节点下)上添加了约5k记录,然后在数据库(在 cut和 user节点上)上查询,但是所有查询都非常慢。我在数据库规则上定义了数据索引,但是它没有用。我该如何解决这个问题?

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?

这是我的查询:

// 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);

推荐答案

如果要继续扩展,最好的方法是是要在区域引用中复制您的数据,在该区域引用中您知道哪个麋鹿/苏。像这样的东西:

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)

然后循环遍历,直接获得每个麋鹿/ su

And then loop through those to go get each elk/su directly

这篇关于在具有大型数据集的Firebase数据库上查询非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆