From fa7cec3bb9ae8dd4c2b145bb9ee8a9dd61fce12b Mon Sep 17 00:00:00 2001 From: Ross Oliver Date: Fri, 17 May 2024 09:31:43 +0100 Subject: [PATCH] Remove unused joins on declarations query As we filter by declaration -> cohort we no longer need to join on other cohorts. Move join on induction records to previous declarations scope as its only used there. --- .../api/v3/participant_declarations_query.rb | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/services/api/v3/participant_declarations_query.rb b/app/services/api/v3/participant_declarations_query.rb index b43b56af6c0..e835e4a28fd 100644 --- a/app/services/api/v3/participant_declarations_query.rb +++ b/app/services/api/v3/participant_declarations_query.rb @@ -75,12 +75,21 @@ def npq_lead_provider end def declarations_scope - scope = with_joins(ParticipantDeclaration.for_lead_provider(cpd_lead_provider)) + scope = ParticipantDeclaration.for_lead_provider(cpd_lead_provider) + .left_outer_joins(:cohort) filter_cohorts(scope) end def ecf_previous_declarations_scope - scope = with_joins(ParticipantDeclaration) + scope = ParticipantDeclaration + .left_outer_joins( + :cohort, + participant_profile: [ + { induction_records: [ + { induction_programme: :partnership }, + ] }, + ], + ) .where(participant_profile: { induction_records: { induction_programme: { partnerships: { lead_provider_id: lead_provider&.id } } } }) .where(participant_profile: { induction_records: { induction_status: "active" } }) # only want induction records that are the winning latest ones .where(state: %w[submitted eligible payable paid]) @@ -103,19 +112,6 @@ def participant_ids def delivery_partner_ids filter[:delivery_partner_id]&.split(",") end - - def with_joins(scope) - scope.left_outer_joins( - :cohort, - participant_profile: [ - [schedule: :cohort], - { induction_records: [ - :cohort, - { induction_programme: :partnership }, - ] }, - ], - ) - end end end end