I am building a hospital management app. In this app there are bunch of features of which major features are messaging, appointment booking, video appointment and much more. In the messaging feature what I am trying to do is loading all the previous messages from cache using bellow code
QuerySnapshot<Map<String, dynamic>> localMessageDocs = await _db
.collection("users")
.doc(AuthService.uid())
.collection("messages")
.orderBy('time', descending: true)
.get(GetOptions(source: Source.cache));
and after that I am querying latest messages using below code
_db
.collection('users')
.doc(AuthService.uid())
.collection('messages')
.where('time', isGreaterThan: _lastLocalMessageTime)
.orderBy('time', descending: true)
.snapshots()
but still I am afraid of bunch of reads that may occur if this system fails, like the cache size allowed in android and the firebase cache limitations(Default is 40MB) as messages for single user can be increase exponentially, which may cause thousand dollar bill. Any help will be appreciated!