Eager loading countries when creating a new zone #3649
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Zones can be created at country or state level, and the
select box that renders the state, it needs the country name
as well, to build this, it calls the mthod state_with_country
and it causes a query n+1, eager loading their countries
improves dramatically the response time when rendering the
new form.
Before
Started GET "/admin/zones/new"
....
Rendered backend/app/views/spree/admin/zones/_state_members.html.erb (Duration: 10392.6ms | Allocations: 10016775)
...
Completed 200 OK in 11247ms (Views: 10958.5ms | ActiveRecord: 257.5ms | Allocations: 11049597)
After
Started GET "/admin/zones/new"
....
Rendered backend/app/views/spree/admin/zones/_state_members.html.erb (Duration: 237.7ms | Allocations: 179137)
...
Completed 200 OK in 1268ms (Views: 1034.5ms | ActiveRecord: 108.2ms | Allocations: 1278890)
Checklist: