Search code examples
androidfirebaseuser-experience

What is the best way to update a local SQLite database when firestore gets updated?


I need suggestions on the best way to update the user's favorites list of movies which is stored locally in a SQLite database on his android phone. There's a separate fragment in the MainActivity where he can access his favorite movies list and sort it by name or by release date or by added, etc. Now I've kinda hacked myself into a roadblock, when all the movies in the backend database get updated, his favorites list stays untouched and of course this is to be expected because his data is stored locally. This causes multiple problems, for example, when he adds a movie with an unofficial release date and on the backend database this movie gets updated with an official release date, the movie release data stays the same as when added in and never changes.

My backend is in firebase firestore and I have thought of multiple solutions but they all can require multiple reads to the firestore depending on the user's favorite list's size.

Two solution that I've thought of that I'm not very fond of using because they both require a lot of reads to the backend.

  • A sync toolbar button that the user clicks on manually which updates all movies with new release date in his list
  • Automatically do the sync operation once a week in the code

What is the best way to update a local SQLite database when the backend gets updated?

And I'd really like to keep his favorites list saved locally, and avoid storing it in the backend because of different reasons notably to save on my firebase bill.


Solution

  • You have no choice but to read every single entry in a user's list and update it accordingly. I understand that a user could have releases on top of releases and that number could go really high, but you have no other option.