2961: Save user information as part of the session cookie, eliminates looking
authorPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 9 Jun 2014 13:09:09 +0000 (09:09 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 9 Jun 2014 13:09:09 +0000 (09:09 -0400)
up current user when rendering every page and panel, this means 2x reduction in
latency when the panel only requires 1 API lookup otherwise.

apps/workbench/app/controllers/application_controller.rb

index fa1b8fae77e7cb0fb2540d805792446f9ade67fa..d225b6e93c7b1f4c57302d102fc4fd54b42752a5 100644 (file)
@@ -180,8 +180,18 @@ class ApplicationController < ActionController::Base
   end
 
   def current_user
+    return Thread.current[:user] if Thread.current[:user]
+
     if Thread.current[:arvados_api_token]
-      Thread.current[:user] ||= User.current
+      if session[:user]
+        if session[:user][:is_active] != true
+          Thread.current[:user] = User.current
+        else
+          Thread.current[:user] = User.new(session[:user])
+        end
+      else
+        Thread.current[:user] = User.current
+      end
     else
       logger.error "No API token in Thread"
       return nil
@@ -275,6 +285,15 @@ class ApplicationController < ActionController::Base
         # call to verify its authenticity.
         if verify_api_token
           session[:arvados_api_token] = params[:api_token]
+          u = User.current
+          session[:user] = {
+            email: u.email,
+            first_name: u.first_name,
+            last_name: u.last_name,
+            is_active: u.is_active,
+            is_admin: u.is_admin,
+            prefs: u.prefs
+          }
           if !request.format.json? and request.method == 'GET'
             # Repeat this request with api_token in the (new) session
             # cookie instead of the query string.  This prevents API