From f83c69f8b0a9a9efbbf99a9d0b2f1403525f16e8 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Jan 2019 17:07:14 -0600 Subject: [PATCH] [miq_provision_virt_workflow.rb] Avoid respond_to? respond_to? calls in mass are slow since they require some object introspection, where doing a simple `nil` check is much quicker. By including just the `cloud_tenant_id` in the SELECT clause, it allows for the swapping of `respond_to?` with an `nil` check, with the functionality that existed preserved. Benchmark --------- **Before** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 28440 | 33 | 1929.5 | 243133 | | 28491 | 33 | 1933.6 | 243133 | | 28858 | 33 | 2631.9 | 243133 | **After** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 27107 | 33 | 1958.5 | 243133 | | 26803 | 33 | 1944.2 | 243133 | | 27642 | 33 | 1965.5 | 243133 | --- app/models/miq_provision_virt_workflow.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/miq_provision_virt_workflow.rb b/app/models/miq_provision_virt_workflow.rb index a567725cf8b..35ae8cbc4c2 100644 --- a/app/models/miq_provision_virt_workflow.rb +++ b/app/models/miq_provision_virt_workflow.rb @@ -340,7 +340,7 @@ def allowed_templates(options = {}) end # Only select the colums we need - vms = vms.select(:id, :name, :guid, :uid_ems, :ems_id) + vms = vms.select(:id, :name, :guid, :uid_ems, :ems_id, :cloud_tenant_id) allowed_templates_list = source_vm_rbac_filter(vms, condition, VM_OR_TEMPLATE_EXTRA_COLS).to_a @allowed_templates_filter = filter_id @@ -1046,7 +1046,7 @@ def create_hash_struct_from_vm_or_template(vm_or_template, options) :allocated_disk_storage => vm_or_template.allocated_disk_storage, :v_total_snapshots => vm_or_template.v_total_snapshots, :evm_object_class => :Vm} - data_hash[:cloud_tenant] = vm_or_template.cloud_tenant if vm_or_template.respond_to?(:cloud_tenant) + 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) end