Firebase EqualTo性能&安全 [英] Firebase EqualTo performance & security
问题描述
equalTo
方法。 ref.orderByChild(userid)。等于(uid).on(child_added,function(snapshot){
console.log(snapshot.val );
});
这是否首先查询所有对象(慢),然后只选择所需要的对象,否则firebase会优化在服务器上查询本身?我来自SQL,我有点不确定如何处理在firebase中的
查询。
编辑:还有安全问题。用户可以通过劫持js代码来接收所有对象?我希望安全规则应该解决这个问题?
示例JSON:
{
Objectkey1:{userid:'uid',...},
Objectkey2:{userid:'uid',...},
...
}
所有的对象(慢),然后只选择所需要的或者firebase在服务器上优化查询本身?
发生什么事情因此,当您将更多项目添加到由 ref
标识的位置时,此操作将始终变慢。
如果该类型(例如,如果您关心可扩展性),请考虑向 uid
标识的用户添加倒数/次级索引。
I have an array of objects related to users and want to get all objects related to one user. I can't save the userid as a parent node but as a child so that I want to use the equalTo
method.
ref.orderByChild("userid").equalTo(uid).on("child_added", function(snapshot) {
console.log(snapshot.val());
});
Does this first query all objects (slow) and then select only the required ones or does firebase optimize the query itself on the server? I come from SQL and I am a bit unsure how to handle where
queries in firebase.
Edit: there are also security issues. A user could receive all objects by hacking the js code? I hope the security rules should solve this?
Example JSON:
{
Objectkey1: { userid: 'uid', ... },
Objectkey2: { userid: 'uid', ... },
...
}
Does this first query all objects (slow) and then select only the required ones or does firebase optimize the query itself on the server?
Yup, that's pretty much what happens. So this operation will always get slower as you add more items to the location identified by ref
.
If that type of performance is a concern (i.e. if you care about scalability), consider adding an inverted/secondary index to the thing that user identified by uid
.
这篇关于Firebase EqualTo性能&安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!