Class: Profiler::Api::ExplainController

Inherits:
Profiler::ApplicationController show all
Defined in:
app/controllers/profiler/api/explain_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/profiler/api/explain_controller.rb', line 10

def create
  unless Profiler.configuration.enabled
    return render json: { error: "EXPLAIN is only available when the profiler is enabled" }, status: :forbidden
  end

  token       = params[:token].to_s
  query_index = params[:query_index].to_i

  if token.blank?
    return render json: { error: "token is required" }, status: :unprocessable_entity
  end

  result = Profiler::ExplainRunner.run(token, query_index)
  render json: result
rescue ArgumentError => e
  render json: { error: e.message }, status: :unprocessable_entity
rescue => e
  render json: { error: e.message }, status: :internal_server_error
end