kphurley / swlcgdb

A Deckbuilder for Star Wars: The Card Game LCG
4 stars 3 forks source link

Add deck and deck_card_block models, with appropriate migration #17

Closed kphurley closed 10 months ago

kphurley commented 10 months ago

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:

[{:card_block_id=>3, :deck_id=>1, :quantity=>1}, {:card_block_id=>2, :deck_id=>1, :quantity=>2}, {:card_block_id=>1, :deck_id=>1, :quantity=>1}]

(Well, json that can convert to this, obviously)

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).