我了解 firestore 缓存和读取费用在这些场景中的表现。我不确定这是否正确。
如果我在一个集合中有 2000 个文档。此集合名称为“testCollection”。这些文档不会更改、更新或删除。我的客户端是 android 已经启用离线持久性和设备当前在线
1.
db.collection("testCollection").onSnapshot(function(doc) {});
收取 2000 次读取费用并缓存这些文档。然后重新打开应用程序并再次运行相同的代码
db.collection("testCollection").onSnapshot(function(doc) {});
另外 2000 次读取收费,因为 firestore 需要检查每个文档是否是最新的。所以 2000+2000 次读取收费
2.
我不确定这是如何表现的。只需一起运行相同的代码
db.collection("testCollection").onSnapshot(function(doc) {});
db.collection("testCollection").onSnapshot(function(doc) {});
Run Code Online (Sandbox Code Playgroud)
我认为 2000 次读取是收费的,因为数据是最新的
3.
db.collection("testCollection").limit(300).onSnapshot(function(doc) {});
db.collection("testCollection").limit(800).onSnapshot(function(doc) {});
Run Code Online (Sandbox Code Playgroud)
总共 1100 次读取收费。因为它是不同的查询。
我有什么误解或错误吗?
我正在尝试使用 firebase 模拟器套件测试 google 登录流程。问题是谷歌登录不是idToken
一直收到,但firebase模拟器套件只支持id_token
,所以我无法通过这种方法登录。
编辑:
Future<UserCredential> signInWithGoogle() async {
// Trigger the authentication flow
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication? googleAuth =
await googleUser?.authentication;
// Create a new credential
final credential = GoogleAuthProvider.credential(
// Didn't fill accessToken arg cause firebase emulator only supports idToken.
// accessToken: googleAuth?.accessToken,
idToken: googleAuth?.idToken,
);
// Once signed in, return the UserCredential
return await firebaseAuth.signInWithCredential(credential);
}
Run Code Online (Sandbox Code Playgroud)
我'accessToken != null …
我正在尝试防止存储滥用。我的目标是每天限制用户上传操作。所以我部署了一个存储 onFinalize 触发器,一旦文件上传,该功能就会检测到一个计数器,该计数器使用 Firestore 是否达到了限制。如果是,像这样将毫秒存储到 CustomUserClaims:
//the user need to wait after this time to continue upload files (timeToUnlock = currentTime + additionalTime)
setCustomUserClaims(uid, {
timeToUnlock: 1570509112055
})
Run Code Online (Sandbox Code Playgroud)
并比较规则
allow create: if request.time.toMillis() >= request.auth.token.timeToUnlock;
Run Code Online (Sandbox Code Playgroud)
但是每次当 setCustomUserClaims 我需要注销并再次登录客户端以更新声明或声明不会更新它只是保留以前的值。我打印 customClaims 到控制台参数已更新但似乎规则中的参数未更新。任何人都有更好的主意解决这个问题?因为如果这不起作用,我不知道要防止这种情况发生,谢谢您的帮助。
console.log((await admin.auth().getUser(uid)).customClaims);
Run Code Online (Sandbox Code Playgroud) google-cloud-storage firebase firebase-security firebase-authentication firebase-admin