Skip to content

Commit

Permalink
fix: n+1 issues in CaseContactsController#index
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticspoon committed Jun 28, 2024
1 parent 2365e96 commit 858bc09
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ def current_organization_groups
end

def all_case_contacts
policy_scope(current_organization.case_contacts).includes(:creator, contact_types: :contact_type_group)
policy_scope(current_organization.case_contacts).includes(
:creator,
:followups,
:contact_types,
contact_topic_answers: [:contact_topic]
)
end

def additional_expense_params
Expand Down
2 changes: 1 addition & 1 deletion app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def contact_groups_with_types
end

def requested_followup
followups.requested.first
followups.find(&:requested?)
end

def should_send_reimbursement_email?
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/case_contact_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ def org_cases
CasaOrg.includes(:casa_cases)
.references(:casa_cases)
.find_by(id: current_user.casa_org_id)
.casa_cases.includes(:case_contacts)
.casa_cases
end
end
4 changes: 2 additions & 2 deletions app/views/casa_cases/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@
<%= render(partial: "case_contacts/case_contact",
collection: @casa_case.decorate
.case_contacts_ordered_by_occurred_at
.includes(contact_types: [:contact_type_group])
.includes(:contact_types)
.grab_all(current_user),
as: :contact) %>
<% else %>
<%= render(partial: "case_contacts/case_contact",
collection: @casa_case.decorate
.case_contacts_filtered_by_active_assignment_ordered_by_occurred_at
.includes(contact_types: [:contact_type_group])
.includes(:contact_types)
.grab_all(current_user),
as: :contact) %>
<% end %>
Expand Down

0 comments on commit 858bc09

Please sign in to comment.