Skip to content

Commit

Permalink
Remove unused joins on declarations query
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ethax-ross committed May 17, 2024
1 parent 5410c2e commit c6807d0
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions app/services/api/v3/participant_declarations_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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

0 comments on commit c6807d0

Please sign in to comment.