diff --git a/config/initializers/mini_profiler.rb b/config/initializers/mini_profiler.rb index f8787a233d89d..7427c5b18787d 100644 --- a/config/initializers/mini_profiler.rb +++ b/config/initializers/mini_profiler.rb @@ -1,7 +1,11 @@ # If Mini Profiler is included via gem if defined?(Rack::MiniProfiler) - Rack::MiniProfiler.config.storage_instance = Rack::MiniProfiler::RedisStore.new(connection: DiscourseRedis.new) + # note, we may want to add some extra security here that disables mini profiler in a multi hosted env unless user global admin + # raw_connection means results are not namespaced + # + # namespacing gets complex, cause mini profiler is in the rack chain way before multisite + Rack::MiniProfiler.config.storage_instance = Rack::MiniProfiler::RedisStore.new(connection: DiscourseRedis.raw_connection) # For our app, let's just show mini profiler always, polling is chatty so nuke that Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env| diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb index 5aae45185a2b5..cc0cd4996f529 100644 --- a/lib/discourse_redis.rb +++ b/lib/discourse_redis.rb @@ -3,11 +3,20 @@ # class DiscourseRedis + def self.raw_connection(config = nil) + config ||= self.config + redis_opts = {host: config['host'], port: config['port'], db: config['db']} + redis_opts[:password] = config['password'] if config['password'] + Redis.new(redis_opts) + end + + def self.config + YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env] + end + def initialize - @config = YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env] - redis_opts = {host: @config['host'], port: @config['port'], db: @config['db']} - redis_opts[:password] = @config['password'] if @config['password'] - @redis = Redis.new(redis_opts) + @config = DiscourseRedis.config + @redis = DiscourseRedis.raw_connection(@config) end # prefix the key with the namespace