Move n+1 detection to around_action hook
This commit is contained in:
parent
76f3b85613
commit
bb82f74e27
1 changed files with 8 additions and 11 deletions
|
|
@ -28,20 +28,10 @@ module Api
|
||||||
render_error(e)
|
render_error(e)
|
||||||
end
|
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
|
##### Hooks
|
||||||
before_action :current_user
|
before_action :current_user
|
||||||
before_action :default_content_type
|
before_action :default_content_type
|
||||||
|
around_action :n_plus_one_detection, unless: -> { Rails.env.production? }
|
||||||
|
|
||||||
##### Responders
|
##### Responders
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
@ -130,6 +120,13 @@ module Api
|
||||||
def restrict_access
|
def restrict_access
|
||||||
raise UnauthorizedError unless current_user
|
raise UnauthorizedError unless current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def n_plus_one_detection
|
||||||
|
Prosopite.scan
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
Prosopite.finish
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue