Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ActiveRecord's .find_each instead of .each whenever possible #5380

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

elia
Copy link
Member

@elia elia commented Sep 13, 2023

Summary

Rubocop 1.56 was released introducing some changes around Rails/FindEach.

Most changes are in specs and not-critical code, the few changes in core models seem innocuous or even improvements for some edge cases (e.g. a store with thousands of stock locations, which is admittedly unlikely anyway).

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@elia elia self-assigned this Sep 13, 2023
@github-actions github-actions bot added changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem changelog:solidus_sample Changes to the solidus_sample gem changelog:repository Changes to the repository not within any gem labels Sep 13, 2023
@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #5380 (d81437c) into main (152b022) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #5380   +/-   ##
=======================================
  Coverage   88.71%   88.71%           
=======================================
  Files         563      563           
  Lines       13896    13896           
=======================================
  Hits        12328    12328           
  Misses       1568     1568           
Files Changed Coverage Δ
...e/app/models/spree/reimbursement_tax_calculator.rb 100.00% <100.00%> (ø)
core/app/models/spree/stock_location.rb 100.00% <100.00%> (ø)
core/app/models/spree/variant.rb 100.00% <100.00%> (ø)
core/lib/spree/core/controller_helpers/order.rb 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@elia elia marked this pull request as ready for review September 13, 2023 08:31
@elia elia requested a review from a team as a code owner September 13, 2023 08:31
Copy link
Contributor

@rainerdema rainerdema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@elia elia merged commit 3994370 into main Sep 13, 2023
4 checks passed
@elia elia deleted the elia/rubocop-update branch September 13, 2023 09:49
@elia elia changed the title Adjust after rubocop changes Use ActiveRecord's .find_each instead of .each whenever possible Sep 26, 2023
@AdnanTheExcellent
Copy link

AdnanTheExcellent commented Oct 31, 2023

@elia I am upgrading to solidus 4.2 and was looking at this PR in the patch notes. I see that all.find_each is being called a few times, which I believe is redundant. you shouldn't need the all anymore.

i.e. Spree::Variant.all.find_each should be Spree::Variant.find_each

see https://edgeguides.rubyonrails.org/active_record_querying.html#retrieving-multiple-objects-in-batches

@tvdeyen
Copy link
Member

tvdeyen commented Nov 2, 2023

@elia we have the same Rubocop warnings in v4.1 as well. Do you think it is ok to backport this PR to v4.1 as well? There shouldn't be any breaking changes in here, right?

@tvdeyen
Copy link
Member

tvdeyen commented Nov 2, 2023

#5484

@elia
Copy link
Member Author

elia commented Nov 2, 2023

you shouldn't need the all anymore.

@AdnanTheExcellent fully agree, can you please send a PR to fix that? I'd be happy to help merge it 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:repository Changes to the repository not within any gem changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem changelog:solidus_sample Changes to the solidus_sample gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants