If we are in the overview menu with some posts displayed and that then those change on the database, then we refresh. The changes are not reflected on the displayed post.
Steps to reproduce
Open the app and go into the overview with a location where there are at least one post
On the firebase console, change the title (or another field) of one of the displayed post
Refresh the overview by swipping down
With the current bug, the posts wont appear updated
Investigation
After investigation, I think that the issue arises from the way we use the Stream provided by the GeoFlutterFire library in the method winthinAsSingleStreamSubscription (that is used in our PostRepository.getNearPosts()).
We currently recreate the stream each time we need to fetch the posts data and then call first() on it to get the data.
I believe the issue comes from the fact that firestore caches some data and so when we fetch new data, even though we re-create the stream, the old data (from cache) are first putted into the stream and only after comes the new one (from server).
This would explain why we don't see the post being updated when refreshing.
Possible solutions
I believe the most appropriate solution is to directly expose the stream in PostRepository and to then adapt the HomeViewModel to be a StreamNotifier.
This should correct the bug and on top of that would have the benefit of providing live updates of the nearby posts without having to refresh (for instance, see the number of votes changing in real time).
(Note that we would still need to refresh if we change location)
Another quicker solution that can be used to temporally deal with the bug is to disable the firestore cache.
Thus, the first element of the created stream will be the one coming from the server.
This is not an ideal solution but should be enough to provide a working product by milestone 1.
If we are in the overview menu with some posts displayed and that then those change on the database, then we refresh. The changes are not reflected on the displayed post.
Steps to reproduce
Investigation
After investigation, I think that the issue arises from the way we use the
Stream
provided by the GeoFlutterFire library in the methodwinthinAsSingleStreamSubscription
(that is used in ourPostRepository.getNearPosts()
). We currently recreate the stream each time we need to fetch the posts data and then callfirst()
on it to get the data. I believe the issue comes from the fact that firestore caches some data and so when we fetch new data, even though we re-create the stream, the old data (from cache) are first putted into the stream and only after comes the new one (from server). This would explain why we don't see the post being updated when refreshing.Possible solutions
I believe the most appropriate solution is to directly expose the stream in
PostRepository
and to then adapt theHomeViewModel
to be aStreamNotifier
. This should correct the bug and on top of that would have the benefit of providing live updates of the nearby posts without having to refresh (for instance, see the number of votes changing in real time). (Note that we would still need to refresh if we change location)Another quicker solution that can be used to temporally deal with the bug is to disable the firestore cache. Thus, the first element of the created stream will be the one coming from the server. This is not an ideal solution but should be enough to provide a working product by milestone 1.