【发布时间】:2020-01-17 01:42:54
【问题描述】:
我有一个颤振应用程序,它根据不同的标准(例如城市、国家、地区等)在 Firestore 数据库中搜索人员。该应用程序具有作为用户输入的标准,可以选择然后单击按钮应用.当点击按钮时,会调用下面的函数:
CollectionReference collectionReference = Firestore.instance.collection("profiles");
void getResults() {
// getQuery is a function that adds 'where' statements
// (e.g., .where("city", isEqualTo: "Paris);
Query query = getQuery(collectionReference, filters);
Stream<QuerySnapshot> snapshots = query.snapshots();
snapshots.map((docs) => docs.documents).listen((onData){
myStreamController.add(onData);
}
}
使用上面的代码,即使现有流包含所需的所有数据,也会创建一个新查询。例如,用户首先检索所有来自法国的人,然后仅通过更新过滤器来检索所有来自巴黎的人。
由于现有信息流已经包含来自巴黎的所有人,是否可以在不创建新信息流/查询的情况下动态更新查询?
我在这里想要实现的是,我希望 Firestore 能够利用缓存,而不是再次检索所有文档。
【问题讨论】:
标签: firebase flutter google-cloud-firestore