Files
openfoodnetwork/app/services/default_country.rb
Maikel Linke cb3cd3e7ea Cache default country simply in memory
This simplifies the code, avoids a method naming collision with Rails
and should be faster as well.
2024-01-04 13:45:36 +11:00

20 lines
397 B
Ruby

# frozen_string_literal: true
class DefaultCountry
def self.id
country.id
end
def self.code
country.iso
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
end
end