【问题标题】:Firebase Firestore rules: will get()'ing the document being checked counted as another read?Firebase Firestore 规则:get()'ing 正在检查的文档是否算作另一次阅读?
【发布时间】:2018-05-11 14:27:17
【问题描述】:

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

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() 会导致检查文档出现get(),是否需要额外阅读?我了解同一文档的多个get() 将只计费一次。但是,在这种情况下,它是特定文档的唯一 get()

编辑 1: 似乎我的问题并不是我的意思。 (我不是以英语为母语的人。)问题是,当get()/users/{userId} 发生在match /users/{userId} 块(而不是子块)中时,get() 是否会导致额外的阅读?换句话说,在使用get() 和使用resource 变量之间(当然是指同一个文档时),成本是否相同?

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-security


    【解决方案1】:

    是的,这将被视为已阅读的文档。任何时候需要读取文档都算在内,从安全规则读取它与从其他代码读取它没有什么不同。

    【讨论】:

    • 那么,请求没有与原始读取合并?就像,如果我读取 resource 变量,它不会算作额外读取。那么,在这种情况下,当我阅读/users/{userId} 时,我将被收取 2 次阅读费用? (我会改写这个问题。)
    猜你喜欢
    • 2018-10-01
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多