Skip to content

Commit

Permalink
mini profiler fix for multisite
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Mar 26, 2013
1 parent 8ce9eef commit 36d60be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion config/initializers/mini_profiler.rb
@@ -1,7 +1,11 @@
# If Mini Profiler is included via gem # If Mini Profiler is included via gem
if defined?(Rack::MiniProfiler) 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 # 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| Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
Expand Down
17 changes: 13 additions & 4 deletions lib/discourse_redis.rb
Expand Up @@ -3,11 +3,20 @@
# #
class DiscourseRedis 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 def initialize
@config = YAML.load(ERB.new(File.new("#{Rails.root}/config/redis.yml").read).result)[Rails.env] @config = DiscourseRedis.config
redis_opts = {host: @config['host'], port: @config['port'], db: @config['db']} @redis = DiscourseRedis.raw_connection(@config)
redis_opts[:password] = @config['password'] if @config['password']
@redis = Redis.new(redis_opts)
end end


# prefix the key with the namespace # prefix the key with the namespace
Expand Down

0 comments on commit 36d60be

Please sign in to comment.