Rat*_*met 6 firebase firebase-security google-cloud-firestore
我在 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);
}
}
Run Code Online (Sandbox Code Playgroud)
isUserDislabled()是一个将在多个地方调用的函数。它将通过get()用户的文档来查看用户是否被禁用。
问题是,第一次调用 会isUserDislabled()导致get()检查文档,从而导致额外的读取成本吗?据我了解,get()同一文档的多个内容将仅收取一次费用。但是,在本例中,它仅get()适用于特定文档。
编辑1:看来我的问题并不完全是我的意思。(我的母语不是英语。)问题是,当get()to/users/{userId}发生在match /users/{userId}块(而不是子块)中时,会get()导致额外读取吗?换句话说,使用get()和使用resource变量之间(当然,当它引用同一个文档时),其成本是否相同?
| 归档时间: |
|
| 查看次数: |
833 次 |
| 最近记录: |