diff --git a/app/models/exchange.rb b/app/models/exchange.rb index 2522d5622d..e52d412c96 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -108,10 +108,13 @@ class Exchange < ApplicationRecord private + # An Order Cycle can have thousands of ExchangeVariants. + # It's a simple association without any callbacks on creation. So we can + # insert in bulk and improve the performance tenfold for large order cycles. def clone_all_exchange_variants(exchange_id) return unless variant_ids.any? - ExchangeVariant.insert_all( + ExchangeVariant.insert_all( # rubocop:disable Rails/SkipsModelValidations variant_ids.map{ |variant_id| { variant_id: variant_id, exchange_id: exchange_id } } ) end