Skip to content

Commit 22d5a14

Browse files
authored
Perf: Refactor dashboard index page (#4874)
1 parent 6bb570b commit 22d5a14

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

app/controllers/dashboard_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ class DashboardController < ApplicationController
44

55
def index
66
@org_stats = OrganizationStats.new(current_organization)
7-
@total_inventory = current_organization.total_inventory
87
@partners_awaiting_review = current_organization.partners.awaiting_review
9-
@outstanding_requests = current_organization.ordered_requests.where(status: %i[pending started]).order(:created_at)
8+
@outstanding_requests = current_organization
9+
.ordered_requests
10+
.includes(:partner_user, :partner)
11+
.where(status: %i[pending started])
12+
.order(:created_at)
13+
.limit(25)
1014

1115
@low_inventory_report = LowInventoryQuery.call(current_organization)
1216

app/views/dashboard/_outstanding_requests.html.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
footer_options: { class: "text-center" },
99
) do
1010
%>
11-
<% if @outstanding_requests.empty? %>
11+
<% if @outstanding_requests.length.zero? %>
1212
No outstanding requests!
1313
<% else %>
1414
<table class="table table-hover striped">
@@ -21,12 +21,12 @@
2121
</tr>
2222
</thead>
2323
<tbody>
24-
<% @outstanding_requests.take(25).each do |item| %>
24+
<% @outstanding_requests.each do |request| %>
2525
<tr>
26-
<td class="date"><%= link_to item.created_at.strftime("%m/%d/%Y"), item %></td>
27-
<td><%= item.partner.name %></td>
28-
<td><%= item.partner_user&.formatted_email %></td>
29-
<td><%= item.comments %></td>
26+
<td class="date"><%= link_to request.created_at.strftime("%m/%d/%Y"), request %></td>
27+
<td><%= request.partner.name %></td>
28+
<td><%= request.partner_user&.formatted_email %></td>
29+
<td><%= request.comments %></td>
3030
</tr>
3131
<% end %>
3232
</tbody>

0 commit comments

Comments
 (0)