Firestore-安全规则:是OR连接中的多次读取,并且将“懒惰”地求值?

问题描述 投票:0回答:1

所以,当我的规则如下时,我的问题是关于一个用例:

match /collection/{docID} {
    allow read,write,update : if isSomethingTrue();
    allow read: if request.auth.uid != null && isOnotherFunctionWithGETInside();
    allow create: if request.auth.uid != null;

}

如果我可以将我的阅读规则翻译为:我是对的吗?

allow read: isSomethingTrue() || (request.auth.uid != null && isOnotherFunctionWithGETInside())

并且如果是,如果isSomething()返回true,第二部分是否不执行?那么它将以惰性模式评估吗?

这对我来说是一个重要的问题,因为如果我仅交换两个允许读取行的顺序(因为在第二次读取中使用了get()函数,那么账单(服务器读取操作)可能会有很大的不同)规则)。

提前感谢。

firebase google-cloud-firestore firebase-security-rules
1个回答
0
投票

您所描述的行为在编程语言中称为“短路”。是的,安全规则将使逻辑“或”短路,以避免评估表达式的其余部分。这在安全性规则的API documentation for booleans中涵盖。

© www.soinside.com 2019 - 2024. All rights reserved.