ProximaEPFL / proxima

A social app that encourages users to visit places in order to see posts.
7 stars 1 forks source link

Posts are not updated correctly on refresh #78

Closed yoannLafore closed 5 months ago

yoannLafore commented 5 months ago

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 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.

yoannLafore commented 5 months ago

The temporary fix of disabling the firestore cache has been applied in #79. But a proper fix is still required.