Provide response[_profile][request_time] if requested by client. refs #1815
authorTom Clegg <tom@curoverse.com>
Tue, 7 Jan 2014 21:07:33 +0000 (13:07 -0800)
committerTom Clegg <tom@curoverse.com>
Tue, 7 Jan 2014 21:07:33 +0000 (13:07 -0800)
services/api/app/controllers/application_controller.rb

index c6e7da0e11391297513a3cf8016d1ea1196d2148..13ee6ab6cc8f41c7c3d924b39957d44b8568605d 100644 (file)
@@ -241,6 +241,7 @@ class ApplicationController < ActionController::Base
   end
 
   def thread_with_auth_info
+    Thread.current[:request_starttime] = Time.now
     Thread.current[:api_url_base] = root_url.sub(/\/$/,'') + '/arvados/v1'
     begin
       user = nil
@@ -363,4 +364,17 @@ class ApplicationController < ActionController::Base
     (request.headers['Accept'].split(' ') &
      ['text/plain', '*/*']).count > 0
   end
+
+  def render *opts
+    response = opts.first[:json]
+    if response &&
+        params[:_profile] &&
+        response.respond_to?(:[]) &&
+        Thread.current[:request_starttime]
+      response[:_profile] = {
+         request_time: Time.now - Thread.current[:request_starttime]
+      }
+    end
+    super *opts
+  end
 end