Skip to content

Commit 2d3c993

Browse files
committed
[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 |
1 parent 9e4f558 commit 2d3c993

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/models/miq_provision_virt_workflow.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def allowed_templates(options = {})
338338
end
339339

340340
# Only select the colums we need
341-
vms = vms.select(:id, :name, :guid, :uid_ems, :ems_id)
341+
vms = vms.select(:id, :name, :guid, :uid_ems, :ems_id, :cloud_tenant_id)
342342

343343
allowed_templates_list = source_vm_rbac_filter(vms, condition, VM_OR_TEMPLATE_EXTRA_COLS).to_a
344344
@allowed_templates_filter = filter_id
@@ -1053,7 +1053,7 @@ def create_hash_struct_from_vm_or_template(vm_or_template, options)
10531053
:allocated_disk_storage => vm_or_template.allocated_disk_storage,
10541054
:v_total_snapshots => vm_or_template.v_total_snapshots,
10551055
:evm_object_class => :Vm}
1056-
data_hash[:cloud_tenant] = vm_or_template.cloud_tenant if vm_or_template.respond_to?(:cloud_tenant)
1056+
data_hash[:cloud_tenant] = vm_or_template.cloud_tenant if vm_or_template.cloud_tenant_id
10571057
if vm_or_template.operating_system.product_name
10581058
data_hash[:operating_system] = MiqHashStruct.new(:product_name => vm_or_template.operating_system.product_name)
10591059
end

0 commit comments

Comments
 (0)