I have a list I need to synchronize with a MySQL database. Here's an example procedure:
I have a table with metadata:
+-------+
| value |
+-------+
| test |
| val |
| smtn |
| foo |
+-------+
When my application starts these values are all loaded from the database and added to a List
. Then at some point in my app, a new value is added to the list locally (without updating the database). At some other point a random value is removed from the list (also locally).
After a while the app closes and tries to synchronize the list with the database. The list might look like this at this point: ["test", "smtn", "added", "also_added"]
. As you can see, some values were removed (compared to the initial table values) and some were added. None of the values changed. Only additions and removals.
Now, to synchronize the list with the database I could delete all rows and insert the updated list to the database, but this seems inefficient.
Is there a better way to do this?