Files
openfoodnetwork/app/models/current_config.rb
Matt-Yorkley c01bab5f27 Wrap commonly-repeated calls to Spree::Config to reduce unnecessary cache reads
These config values are relatively static but in some cases they can be called many times in the same request (like rendering a report or a large list of line_items in BOM). These values will now only get fetched from Redis/Postgres once at most per request/job.
2024-03-26 13:39:16 +00:00

20 lines
661 B
Ruby

# frozen_string_literal: true
# Wraps repeatedly-called configs in a CurrentAttributes object so they only get fetched once
# per request at most, eg: CurrentConfig.get(:available_units) for Spree::Config[:available_units]
class CurrentConfig < ActiveSupport::CurrentAttributes
attribute :display_currency, :hide_cents, :currency_decimal_mark,
:currency_thousands_separator, :currency_symbol_position, :available_units
def get(config_key)
return public_send(config_key) unless public_send(config_key).nil?
public_send("#{config_key}=", Spree::Config.public_send(config_key))
end
def currency
ENV.fetch("CURRENCY")
end
end