about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/setting.rb20
-rw-r--r--app/models/user.rb2
2 files changed, 21 insertions, 1 deletions
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 0a429a62b..f3c65c054 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -9,6 +9,26 @@ class Setting < RailsSettings::Base
   end
 
   class << self
+
+    def [](key)
+      return super(key) unless rails_initialized?
+      
+      val = Rails.cache.fetch(cache_key(key, @object)) do
+        db_val = object(key)
+
+        if db_val
+          default_value = default_settings[key]
+
+          return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash)
+          db_val.value
+        else
+          default_settings[key]
+        end
+      end
+      
+      val
+    end
+
     def all_as_records
       vars    = thing_scoped
       records = vars.map { |r| [r.var, r] }.to_h
diff --git a/app/models/user.rb b/app/models/user.rb
index bf7d04d7c..71d3ee0b8 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 
 class User < ApplicationRecord
-  include RailsSettings::Extend
+  include Settings::Extend
 
   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable