Permalink
Browse files

mini profiler fix for multisite

  • Loading branch information...
SamSaffron committed Mar 25, 2013
1 parent 8ce9eef commit 36d60befbd406b6670090d10c25c5fd8565e03f7
Showing with 18 additions and 5 deletions.
  1. +5 −1 config/initializers/mini_profiler.rb
  2. +13 −4 lib/discourse_redis.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|
View
@@ -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

0 comments on commit 36d60be

Please sign in to comment.