A platform for community discussion. Free, open, simple.
DEV: Add ENV variable for enabling MiniProfiler snapshots (#10690)
Osama Sayegha92d88747e39
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex f626119901e..1d4a19ebe7a 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -31,6 +31,7 @@ class ApplicationController < ActionController::Basebefore_action :check_readonly_modebefore_action :handle_themebefore_action :set_current_user_for_logs+ before_action :set_mp_snapshot_fieldsbefore_action :clear_notificationsaround_action :with_resolved_localebefore_action :set_mobile_view@@ -295,6 +296,12 @@ class ApplicationController < ActionController::Baseresponse.headers["X-Discourse-Route"] = "#{controller_name}/#{action_name}"end+ def set_mp_snapshot_fields+ if defined?(Rack::MiniProfiler)+ Rack::MiniProfiler.add_snapshot_custom_field("application version", Discourse.git_version)+ end+ end+def clear_notificationsif current_user && !@readonly_modediff --git a/config/discourse_defaults.conf b/config/discourse_defaults.confindex 8dadac203e4..c7250354b46 100644--- a/config/discourse_defaults.conf+++ b/config/discourse_defaults.conf@@ -95,6 +95,10 @@ smtp_openssl_verify_mode =# load MiniProfiler in production, to be used by developersload_mini_profiler = true+# Every how many requests should MP profile a request (aka take snapshot)+# Default is never+mini_profiler_snapshots_period = 0+# recommended, cdn used to access assetscdn_url =diff --git a/config/initializers/006-mini_profiler.rb b/config/initializers/006-mini_profiler.rbindex ce3443e051b..6bd862f14dc 100644--- a/config/initializers/006-mini_profiler.rb+++ b/config/initializers/006-mini_profiler.rb@@ -24,7 +24,8 @@ if defined?(Rack::MiniProfiler) && defined?(Rack::MiniProfiler::Config)connection: DiscourseRedis.new(nil, namespace: false))- skip = [+ Rack::MiniProfiler.config.snapshot_every_n_requests = GlobalSetting.mini_profiler_snapshots_period+ Rack::MiniProfiler.config.skip_paths = [/^\/message-bus/,/^\/extra-locales/,/topics\/timings/,@@ -51,10 +52,7 @@ if defined?(Rack::MiniProfiler) && defined?(Rack::MiniProfiler::Config)# we DO NOT WANT mini-profiler loading on anything but real desktops and laptops# so let's rule out all handheld, tablet, and mobile devicesRack::MiniProfiler.config.pre_authorize_cb = lambda do |env|- path = env['PATH_INFO']-- (env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/) &&- !skip.any? { |re| re =~ path }+ env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/end# without a user provider our results will use the ip address for namespacing