【发布时间】:2021-06-08 13:39:10
【问题描述】:
今天我在 Play Store 上推出了一个应用,它在后端使用了 Firestore。 我有一个 spark 帐户(免费帐户),从 firestore 读取的内容限制为 50k。 启动 6 小时后,我的阅读图表显示 38k 阅读。
我读到一些关于 firestore 的内容,“Cloud 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';
});
}
}
【问题讨论】:
标签: firebase flutter google-cloud-firestore