I am using flutter with redux for state management. When the app loads I am loading the data from firestore to populate my redux state. Now the problem is every time the app initializes it makes 800+ document reads. The only source of changes to the user data is the app itself and since firestore local persistence is enabled shouldn't the data load from the local cache instead?..What am I missing?
Interesting thing is, If I disable the internet connection to the device, load the app and then enable the connection, the app still works fine (presumably without the doc reads from the app initialization process since they are coming from the cache).
Basically, the desired behavior would be the app to initializes with the local data and then sync only the updates made by the user to the firebase server.
class _MyAppState extends State<MyApp> {
final store = new Store<AppState>(
appReducer,
initialState: new AppState(isLoading: true, logs: []),
middleware: [thunkMiddleware]);
initState(){
super.initState();
loadData();
}
loadData(){
FirebaseAuth.instance.currentUser().then( (loggedInUser) async {
if(loggedInUser==null){
store.dispatch(SetUser(null));
}
QuerySnapshot logsQuery = await Firestore.instance.collection("/users/"+loggedInUser.uid+"/logs").getDocuments();
List<Log> logs = [];
final logDocs = logsQuery.documents;
for (DocumentSnapshot logDoc in logDocs) {
logs.add(Log.fromFireStoreData(logDoc.documentID, logDoc.data));
}
store.dispatch(SetUserLogs(logs));
}
}
...
}