Skip to content

Commit

Permalink
Merge pull request #328 from wearepal/project-idx-issue
Browse files Browse the repository at this point in the history
Performance update on project index page
  • Loading branch information
paulthatjazz authored Feb 5, 2024
2 parents fbdbb79 + 59677e8 commit 8228f49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ class ProjectsController < ApplicationController
before_action :set_team, only: [:index, :new, :create]

def index
@projects = @team.projects.select(:id, :name, :created_at, :updated_at)
@team_projects = @team.projects.select(:id, :source, :updated_at)
.order(Arel.sql("source->>'name'"))
.pluck(:id, Arel.sql("source->>'name'"), :updated_at)
.map { |id, name, updated_at| OpenStruct.new(id: id, name: name, updated_at: updated_at) }
render layout: "team"
end

Expand Down
10 changes: 5 additions & 5 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<div class="list-group-item list-group-item-light">
<input placeholder="Search" class="form-control" data-action="input->filter#update" autofocus>
</div>
<% @team.projects.sort_by { |project| project.name.downcase }.each do |project| %>
<% @team_projects.sort_by { |project| project.name.downcase }.each do |project| %>
<div class="list-group-item list-group-item-action p-0 align-items-center" data-filter-target="item" style="display: flex;">
<%= link_to project_path(project), class: "list-group-item list-group-item-action border-0" do %>
<%= link_to project_path(project.id), class: "list-group-item list-group-item-action border-0" do %>
<div class="d-flex align-items-center justify-content-between">
<div>
<%= project.name %>
Expand All @@ -23,13 +23,13 @@
<i class="fas fa-chevron-right"></i>
</div>
<% end %>
<%= link_to project_duplicates_path(project), method: :post, class: "px-3 py-2" do %>
<%= link_to project_duplicates_path(project.id), method: :post, class: "px-3 py-2" do %>
<i class="fas fa-clone"></i>
<% end %>
<%= link_to edit_project_path(project), class: "px-3 py-2" do %>
<%= link_to edit_project_path(project.id), class: "px-3 py-2" do %>
<i class="fas fa-edit"></i>
<% end %>
<%= 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 %>
<%= 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 %>
<i class="fas fa-trash-alt"></i>
<% end %>
</div>
Expand Down

0 comments on commit 8228f49

Please sign in to comment.