mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
Cache default country for an hour
The default country usually never changes after the initial setup of an instance.
This commit is contained in:
@@ -6,6 +6,12 @@ module Spree
|
||||
|
||||
validates :name, :iso_name, presence: true
|
||||
|
||||
def self.cached_find_by(attrs)
|
||||
Rails.cache.fetch("countries/#{attrs.hash}", expires_in: 1.hour) do
|
||||
find_by(attrs)
|
||||
end
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
name <=> other.name
|
||||
end
|
||||
|
||||
@@ -10,6 +10,6 @@ class DefaultCountry
|
||||
end
|
||||
|
||||
def self.country
|
||||
Spree::Country.find_by(iso: ENV["DEFAULT_COUNTRY_CODE"]) || Spree::Country.first
|
||||
Spree::Country.cached_find_by(iso: ENV["DEFAULT_COUNTRY_CODE"]) || Spree::Country.first
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user