[PATCH conductor 2/2] BZ#801971 - Scalability: Catalog Images tab, /conductor/pools/1?details_tab=images&only_tab=true, is slow

Tomáš Hrčka thrcka at redhat.com
Thu May 24 12:35:42 UTC 2012


From: Tomas Hrcka <thrcka at redhat.com>

This patch detect duplicate images in deployable.xml and for those images it do only one request to fetch data from iwhd.
---
 src/app/controllers/pools_controller.rb |   15 ++++++++++++---
 src/app/models/deployable.rb            |   11 +++++++++++
 src/app/models/pool.rb                  |   18 +++++++++++++++++-
 src/app/views/pools/_images.html.haml   |   15 ++++++---------
 4 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index 782016b..5229dfd 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -105,9 +105,18 @@ class PoolsController < ApplicationController
     save_breadcrumb(pool_path(@pool, :viewstate => viewstate_id), @pool.name)
     require_privilege(Privilege::VIEW, @pool)
     @statistics = @pool.statistics(current_user)
-    @view = filter_view? ? 'deployments/list' : 'deployments/pretty_view' unless params[:details_tab]
-    if params[:details_tab] == 'deployments'
-      @view = filter_view? ? 'deployments/list' : 'deployments/pretty_view'
+
+    if params[:details_tab]
+      case params[:details_tab]
+        when 'images'
+          #this case covers fetching of unique images and constructing collection for filter table
+          @header = [{:name => "catalog"}, {:name => "deployable"}, {:name => "image"}, {:name => "provider_image"}]
+          @catalog_images = @pool.catalog_images_collection(@pool.catalogs.list_for_user(current_user, Privilege::VIEW))
+        when 'deployments'
+          @view = filter_view? ? 'deployments/list' : 'deployments/pretty_view'
+      end      
+    else
+      @view = filter_view? ? 'deployments/list' : 'deployments/pretty_view'      
     end
 
     #TODO add links to real data for history,properties,permissions
diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb
index 201123f..c99cca2 100644
--- a/src/app/models/deployable.rb
+++ b/src/app/models/deployable.rb
@@ -85,6 +85,17 @@ class Deployable < ActiveRecord::Base
     uuids.map { |uuid| Aeolus::Image::Warehouse::Image.find(uuid) }
   end
 
+  def fetch_unique_images
+    uuids = fetch_image_uuids || []
+    uniq_uuids = uuids.uniq
+    result_hash = {}
+    uniq_uuids.each do |uuid|
+      result_hash[uuid] = { :image => Aeolus::Image::Warehouse::Image.find(uuid), :count => uuids.count(uuid)}
+    end
+    result_hash
+  end
+
+
   def fetch_image_uuids
     deployable = fetch_deployable
     deployable.image_uuids unless deployable.nil?
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index f8daa58..a47a64a 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -165,7 +165,23 @@ class Pool < ActiveRecord::Base
   def self.additional_privilege_target_types
     [Deployment, Instance, Catalog, Quota]
   end
-
+  def catalog_images_collection(catalog_list)
+    catalog_images = []
+    catalog_list.each do |catalog|
+      catalog.deployables.each do |deployable|
+        deployable.fetch_unique_images.each do |key,value|
+          row = {:catalog => catalog.name ,:deployable => deployable.name,
+                 :image => "#{value[:image].name} #{value[:image].uuid}", :provider_images =>[] }
+
+          value[:image].provider_images.each do |provider_image|
+            row[:provider_images] << I18n.t('pools.images.pushed', :uuid => provider_image.uuid, :provider => provider_image.provider_name)
+          end
+          value[:count].times {catalog_images << row}
+        end
+      end
+    end
+    catalog_images
+  end
   private
 
   def self.apply_search_filter(search)
diff --git a/src/app/views/pools/_images.html.haml b/src/app/views/pools/_images.html.haml
index ff43d1d..f63a050 100644
--- a/src/app/views/pools/_images.html.haml
+++ b/src/app/views/pools/_images.html.haml
@@ -5,12 +5,9 @@
         =image_tag 'flash_error_icon.png', :alt => 'Errors'
         =flash[:error]
 -else
-  =filter_table(@header, @catalogs)  do |catalog|
-    - catalog.deployables.each do |deployable|
-      - deployable.fetch_images.compact.each do |image|
-        %tr
-          %td= catalog.name
-          %td= deployable.name
-          %td= "#{image.name} (#{image.uuid})"
-          - image.provider_images.each do |provider_image|
-            %td= t('pools.images.pushed', :uuid => provider_image.uuid, :provider => provider_image.provider_name)
+=filter_table(@header, at catalog_images) do |catalog_image|
+  %tr{:class => cycle('nostripe','stripe')}
+    %td=catalog_image[:catalog]
+    %td=catalog_image[:deployable]
+    %td=catalog_image[:image]
+    %td=catalog_image[:provider_images]
-- 
1.7.10.2




More information about the aeolus-devel mailing list