Reputation: 3004
I have a flutter app that searches for people on Firestore database based on different criteria such as city, country, region, etc. The app has the criteria as user-input that can be chosen then applied with a click of a button. When the button is clicked, the function below is called:
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);
}
}
With the code above, a new query is created even if the existing stream contains all the data that is needed. For example, the user first retrieve all people from France first, then retrieves all the people from Paris only by updating the filter.
Since the existing stream already have all people from Paris, is it possible to dynamically update the query without creating a new stream/query?
What I'm trying to achieve here is that I want Firestore to take advantage the cache instead of retrieving all the documents again.
Upvotes: 2
Views: 2293
Reputation: 317667
Firestore doesn't support dynamically changing the parameters of an active query. If you want to change the filters or ordering of an active query, you will have to stop the first query, create a new Query object, then execute the new query.
Upvotes: 3