X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1974e0e333395ee3eccedc2410441a7b018187da..e89251c160ae409f8af2f9ecae5ffb210ccd0a8d:/services/api/app/controllers/application_controller.rb diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index a771042e52..a65bf3e328 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -77,9 +77,7 @@ class ApplicationController < ActionController::Base end def show - render(text: Oj.dump(@object.as_api_response(nil, select: @select), - mode: :compat).html_safe, - content_type: 'application/json') + send_json @object.as_api_response(nil, select: @select) end def create @@ -181,7 +179,16 @@ class ApplicationController < ActionController::Base err[:error_token] = [Time.now.utc.to_i, "%08x" % rand(16 ** 8)].join("+") status = err.delete(:status) || 422 logger.error "Error #{err[:error_token]}: #{status}" - render json: err, status: status + send_json err, status: status + end + + def send_json response, opts={} + # The obvious render(json: ...) forces a slow JSON encoder. See + # #3021 and commit logs. Might be fixed in Rails 4.1. + render({ + text: Oj.dump(response, mode: :compat).html_safe, + content_type: 'application/json' + }.merge opts) end def find_objects_for_index @@ -443,8 +450,7 @@ class ApplicationController < ActionController::Base except(:limit).except(:offset). count(:id, distinct: true) end - render(text: Oj.dump(@object_list, mode: :compat).html_safe, - content_type: 'application/json') + send_json @object_list end def remote_ip