discourse/config/initializers/006-mini_profiler.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
3.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2013-02-05 13:16:51 -06:00
# If Mini Profiler is included via gem
if Rails.configuration.respond_to?(:load_mini_profiler) && Rails.configuration.load_mini_profiler
require 'rack-mini-profiler'
require 'flamegraph'
begin
require 'memory_profiler'
rescue => e
STDERR.put "#{e} failed to require mini profiler"
end
2014-12-28 20:30:54 -06:00
# initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)
end
if defined?(Rack::MiniProfiler) && defined?(Rack::MiniProfiler::Config)
2013-03-25 01:19:59 -05:00
# 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.new(nil, namespace: false)
)
2013-02-05 13:16:51 -06:00
2015-04-16 21:16:37 -05:00
skip = [
/^\/message-bus/,
/^\/extra-locales/,
2015-04-16 21:16:37 -05:00
/topics\/timings/,
/assets/,
/\/user_avatar\//,
/\/letter_avatar\//,
2015-12-08 23:40:49 -06:00
/\/letter_avatar_proxy\//,
2015-04-16 21:16:37 -05:00
/\/highlight-js\//,
Upgrade to FontAwesome 5 (take two) (#6673) * Add missing icons to set * Revert FA5 revert This reverts commit 42572ff * use new SVG syntax in locales * Noscript page changes (remove login button, center "powered by" footer text) * Cast wider net for SVG icons in settings - include any _icon setting for SVG registry (offers better support for plugin settings) - let themes store multiple pipe-delimited icons in a setting - also replaces broken onebox image icon with SVG reference in cooked post processor * interpolate icons in locales * Fix composer whisper icon alignment * Add support for stacked icons * SECURITY: enforce hostname to match discourse hostname This ensures that the hostname rails uses for various helpers always matches the Discourse hostname * load SVG sprite with pre-initializers * FIX: enable caching on SVG sprites * PERF: use JSONP for SVG sprites so they are served from CDN This avoids needing to deal with CORS for loading of the SVG Note, added the svg- prefix to the filename so we can quickly tell in dev tools what the file is * Add missing SVG sprite JSONP script to CSP * Upgrade to FA 5.5.0 * Add support for all FA4.7 icons - adds complete frontend and backend for renamed FA4.7 icons - improves performance of SvgSprite.bundle and SvgSprite.all_icons * Fix group avatar flair preview - adds an endpoint at /svg-sprites/search/:keyword - adds frontend ajax call that pulls icon in avatar flair preview even when it is not in subset * Remove FA 4.7 font files
2018-11-26 15:49:57 -06:00
/\/svg-sprite\//,
2015-04-16 21:16:37 -05:00
/qunit/,
/srv\/status/,
/commits-widget/,
/^\/cdn_asset/,
/^\/logs/,
/^\/site_customizations/,
2015-05-04 01:11:27 -05:00
/^\/uploads/,
/^\/secure-media-uploads/,
2015-05-04 01:11:27 -05:00
/^\/javascripts\//,
/^\/images\//,
/^\/stylesheets\//,
/^\/favicon\/proxied/
2015-04-16 21:16:37 -05:00
]
# we DO NOT WANT mini-profiler loading on anything but real desktops and laptops
# so let's rule out all handheld, tablet, and mobile devices
2013-02-25 10:42:20 -06:00
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
path = env['PATH_INFO']
2015-04-16 21:16:37 -05:00
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/) &&
2015-04-16 21:49:55 -05:00
!skip.any? { |re| re =~ path }
2013-02-05 13:16:51 -06:00
end
# without a user provider our results will use the ip address for namespacing
# with a load balancer in front this becomes really bad as some results can
# be stored associated with ip1 as the user and retrieved using ip2 causing 404s
Rack::MiniProfiler.config.user_provider = lambda do |env|
2013-03-24 22:36:55 -05:00
request = Rack::Request.new(env)
id = request.cookies["_t"] || request.ip || "unknown"
id = id.to_s
# some security, lets not have these tokens floating about
Digest::MD5.hexdigest(id)
end
2013-02-05 13:16:51 -06:00
Rack::MiniProfiler.config.position = 'left'
Rack::MiniProfiler.config.backtrace_ignores ||= []
Rack::MiniProfiler.config.backtrace_ignores << /lib\/rack\/message_bus.rb/
Rack::MiniProfiler.config.backtrace_ignores << /config\/initializers\/silence_logger/
Rack::MiniProfiler.config.backtrace_ignores << /config\/initializers\/quiet_logger/
Rack::MiniProfiler.config.backtrace_includes = [/^\/?(app|config|lib|test|plugins)/]
2013-08-30 01:44:17 -05:00
# Rack::MiniProfiler.counter_method(ActiveRecord::QueryMethods, 'build_arel')
# Rack::MiniProfiler.counter_method(Array, 'uniq')
2013-02-05 13:16:51 -06:00
# require "#{Rails.root}/vendor/backports/notification"
# inst = Class.new
# class << inst
# def start(name,id,payload)
# if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
# @prf ||= {}
# @prf[id] ||= []
# @prf[id] << Rack::MiniProfiler.start_step("#{payload[:serializer] if name =~ /serialize.serializer/} #{name}")
# end
# end
# def finish(name,id,payload)
# if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
# t = @prf[id].pop
# @prf.delete id unless t
# Rack::MiniProfiler.finish_step t
# end
# end
# end
2013-02-05 13:16:51 -06:00
# disabling for now cause this slows stuff down too much
# ActiveSupport::Notifications.subscribe(/.*/, inst)
# Rack::MiniProfiler.profile_method ActionView::PathResolver, 'find_templates'
end
2015-08-19 01:58:25 -05:00
if ENV["PRINT_EXCEPTIONS"]
trace = TracePoint.new(:raise) do |tp|
puts tp.raised_exception
puts tp.raised_exception.backtrace.join("\n")
puts
end
trace.enable
end