I am calculating weekly leaderboard stats for players of a game, using a service object I created. I am in a situation where if I want to redo the calculations for any particular week, I want to delete the old stats if and only if the new stats were saved successfully.
Roughly my steps:
Instead of adding a flag, you could simply
pluck the id's of the old rows, and then run a new query deleting those. The
delete_all method by definition runs a new query, so there isn't a way to freeze the old results and delete those directly.
You might also try updating the rows directly if many of the fields (say
game_id or something) are the same from week to week...