From 39b3e6efe0c3dd5a3fa504a2df2c093fd8160b7d Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Jan 2019 17:20:20 -0600 Subject: [PATCH] [miq_provision_virt_workflow.rb] Use VmOrTemplate#platform Very large performance improvement from this patch on large collections of templates since it avoids preloading all together, reducing the number of iterations over the VM collection, and the number of support objects needing to be introduced (that would later need to be garbage collected. Benchmark --------- **Before** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 27107 | 33 | 1958.5 | 243133 | | 26803 | 33 | 1944.2 | 243133 | | 27642 | 33 | 1965.5 | 243133 | **After** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 14344 | 33 | 1759.6 | 243133 | | 14631 | 33 | 1729.0 | 243133 | | 13405 | 33 | 1752.3 | 243133 | --- app/models/miq_provision_virt_workflow.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/miq_provision_virt_workflow.rb b/app/models/miq_provision_virt_workflow.rb index b215b40c261..1e4d1568877 100644 --- a/app/models/miq_provision_virt_workflow.rb +++ b/app/models/miq_provision_virt_workflow.rb @@ -298,7 +298,13 @@ def tag_symbol :vm_tags end - VM_OR_TEMPLATE_EXTRA_COLS = %i(mem_cpu cpu_total_cores v_total_snapshots allocated_disk_storage).freeze + VM_OR_TEMPLATE_EXTRA_COLS = %i( + platform + mem_cpu + cpu_total_cores + v_total_snapshots + allocated_disk_storage + ).freeze def allowed_templates(options = {}) # Return pre-selected VM if we are called for cloning if [:clone_to_vm, :clone_to_template].include?(request_type) @@ -355,7 +361,6 @@ def allowed_templates(options = {}) end end - MiqPreloader.preload(allowed_templates_list, %i(operating_system)) @_ems_allowed_templates_cache = {} @allowed_templates_cache = allowed_templates_list.collect do |template| create_hash_struct_from_vm_or_template(template, options) @@ -1055,7 +1060,7 @@ def create_hash_struct_from_vm_or_template(vm_or_template, options) :evm_object_class => :Vm} data_hash[:cloud_tenant] = vm_or_template.cloud_tenant if vm_or_template.cloud_tenant_id if vm_or_template.operating_system - data_hash[:operating_system] = MiqHashStruct.new(:product_name => vm_or_template.operating_system.product_name) + data_hash[:operating_system] = MiqHashStruct.new(:product_name => vm_or_template.operating_system_product_name) end if options[:include_datacenter] == true data_hash[:datacenter_name] = vm_or_template.owning_blue_folder.try(:parent_datacenter).try(:name)