and then call deck.destroy_all_card_blocks before applying a bulk-update via insert_all. This will require us to do any validations at the DB level, since insert_all skips AR validations.
Not sure this is really "best" but in my testing, it's certainly fast. One optimization we can look at making is getting Rails to destroy in a single statement (destroy_all appears to do it one at a time, albeit in one transaction).
Tested this in the rails console with a variety of operations.
To update a deck, we're going to expect a payload of something like this:
(Well, json that can convert to this, obviously)
and then call
deck.destroy_all_card_blocks
before applying a bulk-update viainsert_all
. This will require us to do any validations at the DB level, sinceinsert_all
skips AR validations.Not sure this is really "best" but in my testing, it's certainly fast. One optimization we can look at making is getting Rails to destroy in a single statement (destroy_all appears to do it one at a time, albeit in one transaction).