Firebase Firestore规则:将被检查的文档的get()计算为另一次读取吗? [英] Firebase Firestore rules: will get()'ing the document being checked counted as another read?

查看:49
本文介绍了Firebase Firestore规则:将被检查的文档的get()计算为另一次读取吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firestore安全规则中有这样的代码(仅显示相关部分):

I have a code in Firestore security rules like this (showing only relevant parts):

match /users/{userId} {
    function isUserDisabled(userId) {
        return get(/databases/$(database)/documents/users/$(userId))
                    .data.admin == true;
    }

    allow read:  if true;
    allow write: if request.auth.uid == userId
                 && !isUserDisabled(userId);

    match /posts/{postId} {
        allow read:  if true;
        allow write: if request.auth.uid == userId
                     && !isUserDisabled(userId);
    }
}

isUserDislabled()是一个将在多个位置调用的函数.它将 get()用户文档查看用户是否被禁用.

isUserDislabled() is a function that will be called in multiple places. It will get() the user's document to see if the user is disabled or not.

问题是,第一次调用 isUserDislabled()会导致对检查文档进行 get()的额外调用吗?我了解到同一文档的多个 get()仅会计费一次.但是,在这种情况下,它是特定文档的唯一 get().

The question is, will the first call to isUserDislabled(), which cause a get() to the checking document, cost an additional read? I understand that multiple get() to the same document will be billed only once. However, in this case, it's the only get() for the particular document.

似乎我的问题并不完全是我的意思.(我不是英语母语人士.)问题是,当 match/users中发生 get()/users/{userId} 时/{userId} 块(而不是子块), get()是否会引起其他读取?换句话说,在使用 get()和使用 resource 变量之间(当然,当它指向同一个文档时),它的成本是否相同?

Edit 1: Seems like my question isn't exactly what I meant. (I'm not a native English speaker.) The question is, when the get() to /users/{userId} happens in the match /users/{userId} block (and not the subblock), will the get() cause additional read or not? In other words, between using get() and using resource variable (when it refers to the same document, of course), will it cost the same or not?

推荐答案

是的,将被视为已读取的文档.每当需要读取文档时,它都是这样,从安全规则读取文档与从其他代码读取文档没有什么不同.

Yes, that will count as a document read. Any time a document needs to be read it counts as such, and reading it from security rules is no different than reading it from other code.

这篇关于Firebase Firestore规则:将被检查的文档的get()计算为另一次读取吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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