Update api_controller.rb

Add N+1 detectioin via Prosopite in development/test environments
This commit is contained in:
Justin Edmund 2025-02-07 01:50:58 -08:00
parent 0ad2db92fa
commit e7db082d8b

View file

@ -28,6 +28,17 @@ 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
@ -104,9 +115,9 @@ module Api
def render_not_found_response(object)
render json: ErrorBlueprint.render(nil, error: {
message: "#{object.capitalize} could not be found",
code: 'not_found'
}), status: :not_found
message: "#{object.capitalize} could not be found",
code: 'not_found'
}), status: :not_found
end
def render_unauthorized_response