only write the db state to disk if something changed