10144: preload work_unit children
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index 9f0e40aeead8d08ff0437046c38a7d0d0b3457d4..d0ecfe9af161de37d0972849c9d7d4bec756722b 100644 (file)
@@ -527,7 +527,7 @@ class ApplicationController < ActionController::Base
       if not model_class
         @object = nil
       elsif not params[:uuid].is_a?(String)
-        @object = model_class.where(uuid: params[:uuid]).first
+        @object = object_for_dataclass(model_class, params[:uuid])
       elsif params[:uuid].empty?
         @object = nil
       elsif (model_class != Link and
@@ -535,7 +535,7 @@ class ApplicationController < ActionController::Base
         @name_link = Link.find(params[:uuid])
         @object = model_class.find(@name_link.head_uuid)
       else
-        @object = model_class.find(params[:uuid])
+        @object = object_for_dataclass(model_class, params[:uuid])
       end
     rescue ArvadosApiClient::NotFoundException, ArvadosApiClient::NotLoggedInException, RuntimeError => error
       if error.is_a?(RuntimeError) and (error.message !~ /^argument to find\(/)
@@ -1217,6 +1217,15 @@ class ApplicationController < ActionController::Base
     @objects_for
   end
 
+  # helper method to load objects that are already preloaded
+  helper_method :load_preloaded_objects
+  def load_preloaded_objects objs
+    @objects_for ||= {}
+    objs.each do |obj|
+      @objects_for[obj.uuid] = obj
+    end
+  end
+
   def wiselinks_layout
     'body'
   end