From bb82f74e27a566026ba7b77666635a7c32153983 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 9 Feb 2025 18:04:59 -0800 Subject: [PATCH] Move n+1 detection to around_action hook --- app/controllers/api/v1/api_controller.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index fea34fd..887eeaa 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -28,20 +28,10 @@ module Api render_error(e) end - unless Rails.env.production? - around_action :n_plus_one_detection - - def n_plus_one_detection - Prosopite.scan - yield - ensure - Prosopite.finish - end - end - ##### Hooks before_action :current_user before_action :default_content_type + around_action :n_plus_one_detection, unless: -> { Rails.env.production? } ##### Responders respond_to :json @@ -130,6 +120,13 @@ module Api def restrict_access raise UnauthorizedError unless current_user end + + def n_plus_one_detection + Prosopite.scan + yield + ensure + Prosopite.finish + end end end end