Skip to content

Commit a878f0d

Browse files
authored
Merge pull request #5031 from coalest/fix-n-plus-ones
Fix some N+1s
2 parents d73c67a + 53c510c commit a878f0d

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

app/controllers/adjustments_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def index
1212
.order(created_at: :desc)
1313
.class_filter(filter_params)
1414
.during(helpers.selected_range)
15-
@paginated_adjustments = @adjustments.page(params[:page])
15+
@paginated_adjustments = @adjustments.includes(:line_items, :storage_location).page(params[:page])
1616

1717
@storage_locations = StorageLocation.with_adjustments_for(current_organization).select(:id, :name)
1818
@users = current_organization.users

app/controllers/audits_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class AuditsController < ApplicationController
55

66
def index
77
@selected_location = filter_params[:at_location]
8-
@audits = current_organization.audits.class_filter(filter_params)
8+
@audits = current_organization.audits.includes(:line_items, :storage_location).class_filter(filter_params)
99
@storage_locations = StorageLocation.with_audits_for(current_organization).select(:id, :name)
1010
end
1111

app/controllers/barcode_items_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def index
77
@selected_barcodeable_id = filter_params[:barcodeable_id]
88
@selected_partner_key = filter_params[:by_item_partner_key]
99
@selected_barcode_id = filter_params[:by_value]
10-
@barcode_items = current_organization.barcode_items.class_filter(filter_params)
10+
@barcode_items = current_organization.barcode_items.includes(:item, :barcodeable).class_filter(filter_params)
1111
@selected_item = filter_params[:barcodeable_id]
1212
@selected_partner_key = filter_params[:by_item_partner_key]
1313

app/controllers/distributions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def new
164164
end
165165

166166
def show
167-
@distribution = Distribution.includes(:line_items).includes(:storage_location).find(params[:id])
167+
@distribution = Distribution.includes(:storage_location, line_items: :item).find(params[:id])
168168
@line_items = @distribution.line_items
169169

170170
@total_quantity = @distribution.total_quantity

app/controllers/donations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def edit
8484
end
8585

8686
def show
87-
@donation = Donation.includes(:line_items).find(params[:id])
87+
@donation = Donation.includes(line_items: :item).find(params[:id])
8888
@line_items = @donation.line_items
8989
end
9090

app/controllers/product_drive_participants_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ProductDriveParticipantsController < ApplicationController
66
# TODO: Should there be a :destroy action for this?
77

88
def index
9-
@product_drive_participants = current_organization.product_drive_participants.with_volumes.order(:business_name)
9+
@product_drive_participants = current_organization.product_drive_participants.includes(:donations).with_volumes.order(:business_name)
1010

1111
respond_to do |format|
1212
format.html

app/controllers/purchases_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def edit
6767
end
6868

6969
def show
70-
@purchase = current_organization.purchases.includes(:line_items).find(params[:id])
70+
@purchase = current_organization.purchases.includes(line_items: :item).find(params[:id])
7171
@line_items = @purchase.line_items
7272
end
7373

app/views/adjustments/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<td><%= adjustment.organization.name %></td>
9494
<td><%= adjustment.storage_location.name %></td>
9595
<td><%= adjustment.comment %></td>
96-
<td><%= pluralize(adjustment.line_items.count, 'change') %></td>
96+
<td><%= pluralize(adjustment.line_items.size, 'change') %></td>
9797
<td class="text-right"><%= view_button_to adjustment %></td>
9898
</tr>
9999
<% end %>

0 commit comments

Comments
 (0)