Skip to content

Commit

Permalink
Merge pull request #5868 from elasticspoon/fix/n+1-in-case_contacts#i…
Browse files Browse the repository at this point in the history
…ndex

fix: n+1 issues in case_contacts#index
  • Loading branch information
compwron authored Jun 29, 2024
2 parents b693f89 + 858bc09 commit 48fc965
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 @@ -114,7 +114,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 48fc965

Please sign in to comment.