0
0
Fork 0

Clean up Setting model and remove dead code (#28661)

This commit is contained in:
Claire 2024-01-09 15:01:53 +01:00 committed by GitHub
parent 4e02838832
commit 10203bd57a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 106 deletions

View file

@ -67,10 +67,6 @@ class Setting < ApplicationRecord
end
# rubocop:enable Style/MissingRespondToMissing
def object(var_name)
find_by(var: var_name.to_s)
end
def cache_prefix_by_startup
@cache_prefix_by_startup ||= Digest::MD5.hexdigest(default_settings.to_s)
end
@ -81,16 +77,14 @@ class Setting < ApplicationRecord
def [](key)
Rails.cache.fetch(cache_key(key)) do
db_val = object(key)
db_val = find_by(var: key)
db_val ? db_val.value : default_settings[key]
end
end
# set a setting value by [] notation
def []=(var_name, value)
var_name = var_name.to_s
record = object(var_name) || new(var: var_name)
record = find_or_initialize_by(var: var_name.to_s)
record.value = value
record.save!
end
@ -100,7 +94,7 @@ class Setting < ApplicationRecord
content = Rails.root.join('config', 'settings.yml').read
hash = content.empty? ? {} : YAML.safe_load(ERB.new(content).result, aliases: true).to_hash
@default_settings = hash[Rails.env] || {}
@default_settings = (hash[Rails.env] || {}).freeze
end
end