减少Firestore读操作



今天我在play store上发布了一个应用程序,它的后端使用了firestore。我有一个火花帐户(免费帐户),从firestore读取限制为50k。启动6小时后,我的读取图表显示38k读取。

我读到一些关于firestore的东西,"云firestore 16.0.0版本增加了控制DocumentReference.get()和Query.get()是否应该只从服务器获取数据,只从缓存中获取数据"的能力。

这是我的代码,导致从firestore读取操作。有人可以帮助我修改我的代码,使它不总是调用firestore和检索缓存中的数据。

Future<void> _getUserDetails() async {
String uid = FirebaseAuth.instance.currentUser.uid;
DocumentSnapshot doc = await FirebaseFirestore.instance
.collection('UserDatabase')
.doc(uid)
.get();
if (doc.exists) {
// this will check availability of document
setState(() {
branch = doc.data()['Branch'];
semester = doc.data()['Semester'];
});
} else {
setState(() {
branch = 'User is not available';
semester = 'User is not available';
});
}
}

我也一直在考虑这个问题。在我的应用程序中,我有一个启动屏幕,我计划在启动屏幕内获得我的用户详细信息。之后,数据将被传递到需要某些数据的另一个屏幕。我认为这种方法将节省firestore读取。如果你对这个问题也有想法,请告诉我!

我试图将所有集合存储在一个文档中,我现在遇到了同样的问题…我试图将该集合存储到一个数组中,以使用这些集合并使用该集合过滤数据,以便在我的应用程序上进行更少的读取,因为我有大约200个产品,但每个用户进行1400次读取或更多。

至少我在那里看到了一个使用firebase函数的文档&;Data bundle &;以大幅降低读取成本,但今年firebase功能仅适用于Blaze计划。

这篇文章:https://dev.to/moga/decrease-read-costs-of-firestore-using-firestore-data-bundles-30e9

最新更新