[ARVADOS] created: 55173b4fc7ab41430db35afd4aac1611716c6584

Git user git at public.curoverse.com
Thu May 18 11:43:52 EDT 2017


        at  55173b4fc7ab41430db35afd4aac1611716c6584 (commit)


commit 55173b4fc7ab41430db35afd4aac1611716c6584
Author: radhika <radhika at curoverse.com>
Date:   Thu May 18 11:42:25 2017 -0400

    11710: preload / batch retrieval of children of a container_work_unit

diff --git a/apps/workbench/app/models/container.rb b/apps/workbench/app/models/container.rb
index e683a6e..cf1de69 100644
--- a/apps/workbench/app/models/container.rb
+++ b/apps/workbench/app/models/container.rb
@@ -3,7 +3,7 @@ class Container < ArvadosBase
     false
   end
 
-  def work_unit(label=nil)
-    ContainerWorkUnit.new(self, label, self.uuid)
+  def work_unit(label=nil, child_objects=nil)
+    ContainerWorkUnit.new(self, label, self.uuid, child_objects=child_objects)
   end
 end
diff --git a/apps/workbench/app/models/container_request.rb b/apps/workbench/app/models/container_request.rb
index aae712b..7cbd91e 100644
--- a/apps/workbench/app/models/container_request.rb
+++ b/apps/workbench/app/models/container_request.rb
@@ -11,7 +11,7 @@ class ContainerRequest < ArvadosBase
     true
   end
 
-  def work_unit(label=nil)
-    ContainerWorkUnit.new(self, label, self.uuid)
+  def work_unit(label=nil, child_objects=nil)
+    ContainerWorkUnit.new(self, label, self.uuid, child_objects=child_objects)
   end
 end
diff --git a/apps/workbench/app/models/container_work_unit.rb b/apps/workbench/app/models/container_work_unit.rb
index afdc91e..73f2ee3 100644
--- a/apps/workbench/app/models/container_work_unit.rb
+++ b/apps/workbench/app/models/container_work_unit.rb
@@ -1,14 +1,16 @@
 class ContainerWorkUnit < ProxyWorkUnit
   attr_accessor :container
+  attr_accessor :child_proxies
 
-  def initialize proxied, label, parent
-    super
+  def initialize proxied, label, parent, child_objects=nil
+    super proxied, label, parent
     if @proxied.is_a?(ContainerRequest)
       container_uuid = get(:container_uuid)
       if container_uuid
         @container = Container.find(container_uuid)
       end
     end
+    @child_proxies = child_objects
   end
 
   def children
@@ -19,12 +21,22 @@ class ContainerWorkUnit < ProxyWorkUnit
 
     items = []
     if container_uuid
-      reqs = ContainerRequest.where(requesting_container_uuid: container_uuid).results
-      reqs.each do |cr|
-        items << cr.work_unit(cr.name || 'this container')
+      my_children = @child_proxies
+      my_children = ContainerRequest.where(requesting_container_uuid: container_uuid).results if !my_children
+
+      my_child_containers = my_children.map(&:container_uuid).compact.uniq
+      grandchildren = {}
+      my_child_containers.each { |c| grandchildren[c] = []} if my_child_containers
+
+      reqs = ContainerRequest.where(requesting_container_uuid: my_child_containers).results if !my_child_containers
+      reqs.each {|cr| grandchildren[cr.request_container_uuid] << cr} if reqs
+
+      my_children.each do |cr|
+        items << cr.work_unit(cr.name || 'this container', child_objects=grandchildren[cr.container_uuid])
       end
     end
 
+    @child_proxies = nil #no need of this any longer
     @my_children = items
   end
 
diff --git a/apps/workbench/app/views/work_units/_show_status.html.erb b/apps/workbench/app/views/work_units/_show_status.html.erb
index f2052ef..c06e82a 100644
--- a/apps/workbench/app/views/work_units/_show_status.html.erb
+++ b/apps/workbench/app/views/work_units/_show_status.html.erb
@@ -1,6 +1,22 @@
+<%
+    container_uuid = if @object.is_a?(Container) then @object.uuid elsif @object.is_a?(ContainerRequest) then @object.container_uuid end
+    if container_uuid
+      reqs = ContainerRequest.where(requesting_container_uuid: container_uuid).results
+      load_preloaded_objects(reqs)
+
+      child_cs = reqs.map(&:requesting_container_uuid).uniq
+      child_cs += reqs.map(&:container_uuid).uniq
+      preload_objects_for_dataclass(Container, child_cs)
+
+      wu = current_obj.work_unit(name, child_objects=reqs)
+    else
+      wu = current_obj.work_unit(name)
+    end
+%>
+
 <div class="arv-log-refresh-control"
      data-load-throttle="86486400000" <%# 1001 nights %>
      ></div>
 <%=
-   render(partial: 'work_units/show_component', locals: {wu: current_obj.work_unit(name)})
+   render(partial: 'work_units/show_component', locals: {wu: wu})
 %>

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list