【发布时间】:2020-04-12 05:12:25
【问题描述】:
我正在使用 React Native 构建一个游戏,用户每 6 秒左右生成一次卡片。然后通过我设置的 Firebase 连接将这些卡片上传到 Google Firestore。
用户以每 6 秒 1 张的速度生成卡片:每 6 秒 1 张 = 每分钟 10 张 = 每小时 600 张。按照 Google Firebase 每天 20,000 次免费写入的默认配额,我将超过每天允许的最大限额,该服务仅允许 34 人使用一个小时。
为了解决这个问题,我实施了一个临时解决方案,即通过 AsyncStorage 将卡片及其数据存储在用户的本地存储中,然后在“溢出”超过一定限制时将其上传。我的代码大致如下:
// Retrieve the user's inventory.
// Add the new card to the inventory.
// If the inventory length is greater than 15, batch write it all up to Firestore.
这是一种高效且安全的方式来处理快速到来的大量数据吗?
【问题讨论】:
标签: javascript firebase react-native google-cloud-firestore asyncstorage