在具有大型数据集的Firebase数据库上查询非常慢

编程入门 行业动态 更新时间:2024-10-27 10:32:19
本文介绍了在具有大型数据集的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数据库上查询非常慢

本文发布于:2023-07-26 09:34:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1215527.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   数据   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!