android - 所有写入操作的 Firebase 函数
问题描述
我有一个类似于社交媒体应用程序的东西,它具有复杂的写入操作,例如关注请求。
Firestore 规则写得如此之好,以至于没有人可以向我的数据库写入内容。
现在,如果有人想关注用户,客户端会调用带有 uid 参数的云函数,然后云函数正在执行带有多个写入操作的事务。
我这样做是因为可以随时修改事务,因此不需要客户端更新。
所以我的问题是:对我的应用程序中的所有写入操作使用 Cloud Functions 是否不好,我是否错过了这种方法的缺点?
解决方案
将 Cloud Functions 用于我的应用程序中的所有写入操作是否很糟糕?
从定义上讲,这还不错,但从定义上讲也不好。这完全取决于您的用例和实现。
有几点需要考虑:
您的数据修改器的安全规则现在基本上已编码在您的 Cloud Functions 中。所以您的云功能安全了吗?您确定只有授权用户才能呼叫他们吗?
您是否考虑让您的客户将他们的“关注此用户”请求写入 Cloud Firestore 中的特殊“客户请求”集合?您可以让 Cloud Functions 监控对该集合的写入,这有其优势。
For example: since the clients write to Firestore in this scenario, their write operations will not fail when they're offline, but instead be sent to the server (and processed there) when they're back online. In your current scenario you'd have to implement such retry-logic yourself.
推荐阅读
- javascript - 仅使用纯 JavaScript 手动触发下拉事件?
- python - mypy `TypedDict` 的工厂函数
- python - 带有嵌套 JSON 对象的 Pandas
- spring - 如何在 Spring Security 中使用 Restcall
- kubernetes - ConfigMap Kubernetes YAML:值中的空间导致错误
- key-value-store - 如何使用键值存储数据库存储大值(10MB)?
- racket - 如何从带有球拍的列表中获取第二大数字
- excel - 尝试保存时出现错误数量的参数错误?
- sql - 1 个月未访问 SQL Server 数据库
- vb.net - 如何在 Visual Basic 中更改按钮的属性