Skip to content

Commit

Permalink
Fix performance regression
Browse files Browse the repository at this point in the history
Collecting results of large code counts can exceed available memory.

This was initially proposed on another PR that we are basing this one
on: #5383

Co-authored-by: Jared Norman <[email protected]>
Co-authored-by: Nick <[email protected]>
Co-authored-by: Benjamin <[email protected]>
Co-authored-by: Sofia <[email protected]>
Co-authored-by: Senem Soy <[email protected]>
Co-authored-by: Andrew Stewart <[email protected]>
Co-authored-by: Chris <[email protected]>
  • Loading branch information
8 people committed Aug 16, 2024
1 parent d7e3688 commit 211110a
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def generate_random_codes
new_codes = Array.new(max_codes_to_generate) { generate_random_code }.uniq
codes_for_current_batch = get_unique_codes(new_codes)

codes_for_current_batch = codes_for_current_batch.map do |value|
codes_for_current_batch.filter! do |value|
Spree::PromotionCode.create!(
value: value,
promotion: promotion,
promotion_code_batch: promotion_code_batch
)
rescue ActiveRecord::RecordInvalid
nil
end.compact
false
end
created_codes += codes_for_current_batch.size
end
end
Expand Down

0 comments on commit 211110a

Please sign in to comment.