Skip to content

Commit

Permalink
Avoid extra sql query
Browse files Browse the repository at this point in the history
Retreive the applicant email address directly instead of using the
application instance.
  • Loading branch information
fumimowdan committed Sep 19, 2023
1 parent 61c6a39 commit 9a5a754
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/services/submit_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def submit_form!

def create_application_records
ActiveRecord::Base.transaction do
school = create_school
applicant = create_applicant(school)
@application = create_application(applicant)
create_school
create_applicant
create_application
delete_form
end
end

def create_school
School.create!(
@school = School.create!(
name: form.school_name,
headteacher_name: form.school_headteacher_name,
address_attributes: {
Expand All @@ -56,8 +56,8 @@ def create_school
)
end

def create_applicant(school)
Applicant.create!(
def create_applicant
@applicant = Applicant.create!(
ip_address: ip_address,
given_name: form.given_name,
middle_name: form.middle_name,
Expand All @@ -75,13 +75,13 @@ def create_applicant(school)
city: form.city,
postcode: form.postcode,
},
school: school,
school: @school,
)
end

def create_application(applicant)
Application.create!(
applicant: applicant,
def create_application
@application = Application.create!(
applicant: @applicant,
application_date: Date.current.to_s,
application_route: form.application_route,
application_progress: ApplicationProgress.new,
Expand All @@ -100,7 +100,7 @@ def delete_form
def send_applicant_email
GovukNotifyMailer
.with(
email: application.applicant.email_address,
email: @applicant.email_address,
urn: application.urn,
)
.application_submission
Expand Down

0 comments on commit 9a5a754

Please sign in to comment.