From ea6efa9164b67cb529da59fb5ba7979d1cccfa4e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 28 Jan 2025 13:12:28 +1100 Subject: [PATCH 1/2] Simplify default country code lookup The code was using the code from the environment variables to load a reocrd from the database to then return the initial code again. The only use of `DefaultCountry.code` is currently in the geocoder JS compilation. Now it doesn't need the database anymore. --- app/services/default_country.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/services/default_country.rb b/app/services/default_country.rb index 0e07d5c68c..b830f70dcb 100644 --- a/app/services/default_country.rb +++ b/app/services/default_country.rb @@ -5,15 +5,14 @@ class DefaultCountry country.id end + # Two letter code defined in ISO-3166-1. def self.code - country.iso + # Changing ENV requires restarting the process. + ENV.fetch("DEFAULT_COUNTRY_CODE", nil) end def self.country - # Changing ENV requires restarting the process. - iso = ENV.fetch("DEFAULT_COUNTRY_CODE", nil) - # When ENV changes on restart, this cache will be reset as well. - @country ||= Spree::Country.find_by(iso:) || Spree::Country.first + @country ||= Spree::Country.find_by(iso: code) || Spree::Country.first end end From e1f62148c9e840a61d9dba6aadc403d7cf4e88f7 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 28 Jan 2025 13:26:42 +1100 Subject: [PATCH 2/2] Remove now unnecessary country seeding for assets --- .github/workflows/build.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0443fc530a..526328ad8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,6 @@ jobs: - name: Set up database run: | bin/rails db:create db:schema:load - bin/rails runner spec/support/seeds.rb # Asset compile needs a country. - name: Run tests env: @@ -213,7 +212,6 @@ jobs: - name: Set up database run: | bin/rails db:create db:schema:load - bin/rails runner spec/support/seeds.rb # Asset compile needs a country. - name: Run tests @@ -301,7 +299,6 @@ jobs: - name: Set up database run: | bin/rails db:create db:schema:load - bin/rails runner spec/support/seeds.rb # Asset compile needs a country. - name: Run tests @@ -390,7 +387,6 @@ jobs: - name: Set up database run: | bin/rails db:create db:schema:load - bin/rails runner spec/support/seeds.rb # Asset compile needs a country. - name: Run tests @@ -470,7 +466,6 @@ jobs: - name: Set up database run: | bin/rails db:create db:schema:load - bin/rails runner spec/support/seeds.rb # Asset compile needs a country. - name: Run tests env: