如何限制从Firebase读取数据的速率? [英] How to limit rate of data reads from Firebase?

查看:82
本文介绍了如何限制从Firebase读取数据的速率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想限制每个用户从实时数据库读取数据的速率.有很好的方法来限制写入内容,例如此处,但我找不到关于如何限制数据读取的任何解决方案.

I would like to limit the rate of data reads per user from the Realtime Database. There are good ways to limit writes like described here but I can't find any solution on how to limit data reads.

这可以通过安全规则,云功能来完成,还是可以将其限制在Firebase帐户中的某个位置?我已经检查了文档,但是找不到答案.

Can this be done with Security Rules, Cloud Functions or can I limit it somewhere in the Firebase account? I have checked the documentation but can't find the answer.

推荐答案

这适用于实时数据库和Firestore,但使用不同的术语除外. (位置==文档)

This applies to both Realtime Database and Firestore, except with different terminology. (Location == document)

每次执行读取操作时,都必须在数据库的某个位置写入一些值,否则您将无法执行此操作.您不能在安全规则中写入位置,也不能强制客户端在读取的同时进行写入.

You won't be able to do this without also writing some value at a location in the database every time a read is performed. You can't write a location in a security rule, and you can't force the client to write at the same time as a read.

即使您能够在规则中写入要用于速率限制的位置,您也必须在每次必须限制的读取中读取该位置,而这违反了速率限制的目的(因为他们可以继续尝试以只会导致更多读取的方式读取受限制的位置).

Even if you were able to write a location in a rule to use in a rate limit, you would then have to read that location for every read that must be limited, and that kind of defeats the purpose of a rate limit (since they could continue to try to read a restricted location in a way that just causes more reads to happen).

这篇关于如何限制从Firebase读取数据的速率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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