From 636b365304966bd5ff64b4cdcc08753fb765415f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 12 May 2023 10:30:47 +1000 Subject: [PATCH] Tell Rubocop and devs about bulk insert --- app/models/exchange.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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