Skip to content

Commit 59677e8

Browse files
committed
Performance update on project idx page
1 parent fbdbb79 commit 59677e8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

app/controllers/projects_controller.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ class ProjectsController < ApplicationController
22
before_action :set_team, only: [:index, :new, :create]
33

44
def index
5-
@projects = @team.projects.select(:id, :name, :created_at, :updated_at)
5+
@team_projects = @team.projects.select(:id, :source, :updated_at)
6+
.order(Arel.sql("source->>'name'"))
7+
.pluck(:id, Arel.sql("source->>'name'"), :updated_at)
8+
.map { |id, name, updated_at| OpenStruct.new(id: id, name: name, updated_at: updated_at) }
69
render layout: "team"
710
end
811

app/views/projects/index.html.erb

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<div class="list-group-item list-group-item-light">
1010
<input placeholder="Search" class="form-control" data-action="input->filter#update" autofocus>
1111
</div>
12-
<% @team.projects.sort_by { |project| project.name.downcase }.each do |project| %>
12+
<% @team_projects.sort_by { |project| project.name.downcase }.each do |project| %>
1313
<div class="list-group-item list-group-item-action p-0 align-items-center" data-filter-target="item" style="display: flex;">
14-
<%= link_to project_path(project), class: "list-group-item list-group-item-action border-0" do %>
14+
<%= link_to project_path(project.id), class: "list-group-item list-group-item-action border-0" do %>
1515
<div class="d-flex align-items-center justify-content-between">
1616
<div>
1717
<%= project.name %>
@@ -23,13 +23,13 @@
2323
<i class="fas fa-chevron-right"></i>
2424
</div>
2525
<% end %>
26-
<%= link_to project_duplicates_path(project), method: :post, class: "px-3 py-2" do %>
26+
<%= link_to project_duplicates_path(project.id), method: :post, class: "px-3 py-2" do %>
2727
<i class="fas fa-clone"></i>
2828
<% end %>
29-
<%= link_to edit_project_path(project), class: "px-3 py-2" do %>
29+
<%= link_to edit_project_path(project.id), class: "px-3 py-2" do %>
3030
<i class="fas fa-edit"></i>
3131
<% end %>
32-
<%= link_to project_path(project), method: :delete, data: { confirm: "Are you sure you want to delete '#{project.name}'?" }, class: "px-3 py-2 text-danger" do %>
32+
<%= link_to project_path(project.id), method: :delete, data: { confirm: "Are you sure you want to delete '#{project.name}'?" }, class: "px-3 py-2 text-danger" do %>
3333
<i class="fas fa-trash-alt"></i>
3434
<% end %>
3535
</div>

0 commit comments

Comments
 (0)