Merge pull request #8637 from tchak/revert-graphql-trace
Revert "Merge pull request #8635 from tchak/graphql-with-traces"
This commit is contained in:
commit
de11d97df9
1 changed files with 5 additions and 31 deletions
|
@ -1,6 +1,10 @@
|
||||||
class API::V2::GraphqlController < API::V2::BaseController
|
class API::V2::GraphqlController < API::V2::BaseController
|
||||||
def execute
|
def execute
|
||||||
result = tracing? ? instrumented { perform_query } : perform_query
|
result = API::V2::Schema.execute(query,
|
||||||
|
variables: variables,
|
||||||
|
context: context,
|
||||||
|
operation_name: params[:operationName])
|
||||||
|
|
||||||
render json: result
|
render json: result
|
||||||
rescue GraphQL::ParseError, JSON::ParserError => exception
|
rescue GraphQL::ParseError, JSON::ParserError => exception
|
||||||
handle_parse_error(exception)
|
handle_parse_error(exception)
|
||||||
|
@ -14,13 +18,6 @@ class API::V2::GraphqlController < API::V2::BaseController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def perform_query
|
|
||||||
API::V2::Schema.execute(query,
|
|
||||||
variables: variables,
|
|
||||||
context: context,
|
|
||||||
operation_name: params[:operationName])
|
|
||||||
end
|
|
||||||
|
|
||||||
def append_info_to_payload(payload)
|
def append_info_to_payload(payload)
|
||||||
super
|
super
|
||||||
|
|
||||||
|
@ -127,27 +124,4 @@ class API::V2::GraphqlController < API::V2::BaseController
|
||||||
data: nil
|
data: nil
|
||||||
}, status: 500
|
}, status: 500
|
||||||
end
|
end
|
||||||
|
|
||||||
def tracing?
|
|
||||||
params[:tracing].present? && (Rails.env.development? || manager?)
|
|
||||||
end
|
|
||||||
|
|
||||||
def manager?
|
|
||||||
administrateur_signed_in? && AdministrateursProcedure.exists?(administrateur: current_administrateur, manager: true)
|
|
||||||
end
|
|
||||||
|
|
||||||
def instrumented
|
|
||||||
events = []
|
|
||||||
ActiveSupport::Notifications.subscribed(-> (_name, start, finish, _id, payload) { events << { start: Time.zone.at(start), duration: (finish - start) * 1000, sql: payload[:sql] } }, "sql.active_record", monotonic: true) do
|
|
||||||
result = yield
|
|
||||||
result.merge(extensions: {
|
|
||||||
tracing: {
|
|
||||||
startTime: events.first[:start],
|
|
||||||
endTime: events.last[:start],
|
|
||||||
duration: events.sum { _1[:duration] },
|
|
||||||
events: events.sort_by { _1[:duration] }.reverse
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue