From aad9eedcec0453846af2ed247497bb80aab41396 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 27 Sep 2023 11:39:21 +0100 Subject: [PATCH] Update seeds to avoid extra call to database This moves where we set subject limited in the seeds to use the existing list of hashes rather than an additional call to the database. --- db/seeds.rb | 72 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index edf50c6314..97ebddbe0d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -240,31 +240,51 @@ "PT" => [{ status_check: "written", sanction_check: "written" }], "DK" => [{ status_check: "written" }], "FI" => [{ status_check: "written" }], - "GH" => [ - { - requires_preliminary_check: true, - status_check: "online", - sanction_check: "online", - }, - ], + "GH" => { + subject_limited: true, + regions: [ + { + requires_preliminary_check: true, + status_check: "online", + sanction_check: "online", + }, + ], + }, "HK" => [{ status_check: "written", sanction_check: "written" }], - "IN" => [], - "JM" => [{ status_check: "written", sanction_check: "written" }], - "NG" => [ - { - requires_preliminary_check: true, - status_check: "written", - sanction_check: "written", - teaching_authority_provides_written_statement: true, - teaching_authority_name: - "Teachers Registration Council of Nigeria (TRCN)", - teaching_authority_certificate: "Letter of Professional Standing", - }, - ], - "SG" => [{ status_check: "online" }], - "ZA" => [{ status_check: "written", sanction_check: "written" }], + "IN" => { + subject_limited: true, + }, + "JM" => { + subject_limited: true, + regions: [{ status_check: "written", sanction_check: "written" }], + }, + "NG" => { + subject_limited: true, + regions: [ + { + requires_preliminary_check: true, + status_check: "written", + sanction_check: "written", + teaching_authority_provides_written_statement: true, + teaching_authority_name: + "Teachers Registration Council of Nigeria (TRCN)", + teaching_authority_certificate: "Letter of Professional Standing", + }, + ], + }, + "SG" => { + subject_limited: true, + regions: [{ status_check: "online" }], + }, + "ZA" => { + subject_limited: true, + regions: [{ status_check: "written", sanction_check: "written" }], + }, "UA" => [{ reduced_evidence_accepted: true }], - "ZW" => [{ status_check: "written" }], + "ZW" => { + subject_limited: true, + regions: [{ status_check: "written" }], + }, "GG" => [], "JE" => [], }.freeze @@ -274,7 +294,7 @@ DEFAULT_REGION = { name: "" }.freeze COUNTRIES.each do |code, value| - regions = value.is_a?(Hash) ? value[:regions] : value + regions = value.is_a?(Hash) ? value.fetch(:regions, []) : value country_hash = value.is_a?(Hash) ? value.except(:regions) : {} country = @@ -369,7 +389,3 @@ name: english_language_provider[:name], ).update!(english_language_provider.except(:name)) end - -subject_limited_countries = %w[GH IN JM NG SG ZA ZW] - -Country.where(code: subject_limited_countries).update_all(subject_limited: true)