diff --git a/Gemfile b/Gemfile index eb310d43..230b5843 100644 --- a/Gemfile +++ b/Gemfile @@ -65,3 +65,8 @@ gem 'record_tag_helper', '~> 1.0', '>= 1.0.1' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '~> 1.16', require: false + +# For investigating performance issues. +gem "rack-mini-profiler", "~> 3.1" +gem "memory_profiler", "~> 1.0" +gem "stackprof", "~> 0.2.25" diff --git a/Gemfile.lock b/Gemfile.lock index d71bd61c..dd4e66c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -154,6 +154,7 @@ GEM net-pop net-smtp marcel (1.0.2) + memory_profiler (1.0.1) mime-types (3.4.1) mime-types-data (~> 3.2015) mime-types-data (3.2023.0218.1) @@ -189,6 +190,8 @@ GEM rack (2.2.8) rack-attack (6.7.0) rack (>= 1.0, < 4) + rack-mini-profiler (3.1.1) + rack (>= 1.2.0) rack-session (1.0.1) rack (< 3) rack-test (2.1.0) @@ -273,6 +276,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + stackprof (0.2.25) stringio (3.0.8) temple (0.8.2) terser (1.1.17) @@ -314,11 +318,13 @@ DEPENDENCIES httparty (~> 0.21.0) jsbundling-rails (~> 1.1) letter_opener (~> 1.8, >= 1.8.1) + memory_profiler (~> 1.0) mysql2 (~> 0.5.5) nokogiri (~> 1.15, >= 1.15.3) parallel (~> 1.23) puma (~> 6.3, >= 6.3.1) rack-attack (~> 6.7) + rack-mini-profiler (~> 3.1) rails (~> 7.1, >= 7.1.1) rails-i18n (~> 7.0, >= 7.0.7) rdiscount (~> 2.2, >= 2.2.7.1) @@ -328,6 +334,7 @@ DEPENDENCIES sanitize (~> 6.0, >= 6.0.2) sass-rails (~> 6.0) sprockets (~> 4.2) + stackprof (~> 0.2.25) terser (~> 1.1, >= 1.1.17) web-console (~> 4.2) will_paginate (~> 4.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 92e0a417..d29ab94a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,6 +13,13 @@ class ApplicationController < ActionController::Base before_action :save_return_to_path, if: ->(c) { c.controller_name == 'sessions' && c.action_name == 'new' } + # Enable profiling tools if logged in as admin. + before_action do + if current_user && current_user.admin? + Rack::MiniProfiler.authorize_request + end + end + def authenticate_user! redirect_to(new_auth_user_session_path) unless user_signed_in? end diff --git a/config/initializers/rack_mini_profiler.rb b/config/initializers/rack_mini_profiler.rb new file mode 100644 index 00000000..0cb95573 --- /dev/null +++ b/config/initializers/rack_mini_profiler.rb @@ -0,0 +1,3 @@ +Rails.configuration.to_prepare do + Rack::MiniProfiler.config.enable_advanced_debugging_tools = true +end diff --git a/vendor/cache/memory_profiler-1.0.1.gem b/vendor/cache/memory_profiler-1.0.1.gem new file mode 100644 index 00000000..423255dc Binary files /dev/null and b/vendor/cache/memory_profiler-1.0.1.gem differ diff --git a/vendor/cache/rack-mini-profiler-3.1.1.gem b/vendor/cache/rack-mini-profiler-3.1.1.gem new file mode 100644 index 00000000..ac09e439 Binary files /dev/null and b/vendor/cache/rack-mini-profiler-3.1.1.gem differ diff --git a/vendor/cache/stackprof-0.2.25.gem b/vendor/cache/stackprof-0.2.25.gem new file mode 100644 index 00000000..f27a00ad Binary files /dev/null and b/vendor/cache/stackprof-0.2.25.gem differ