Skip to content

Commit

Permalink
Use nested hashes instead of string keys
Browse files Browse the repository at this point in the history
This avoids needing to generate a new string value for each key on
setting of the value and retrieving, and the extra hashes are not a huge
consumer of space.

Of note, the keys are now not strings at all.  Top level will be the
class names, and the child keys will be just the raw IDs.  The
@ems_xml_nodes value is not used anywhere besides the lookup that was
changed in this commit, so the change of this structure should not have
an adverse affect... hopefully...
  • Loading branch information
NickLaMuro committed Apr 27, 2018
1 parent 7f77ae9 commit ef73d6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions app/models/miq_request_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,12 @@ def find_classes_under_ci(item, klass)

def load_ems_node(item, log_header)
@ems_xml_nodes ||= {}
klass_name = item.kind_of?(MiqHashStruct) ? item.evm_object_class : item.class.base_class.name
node = @ems_xml_nodes["#{klass_name}_#{item.id}"]
klass_name = if item.kind_of?(MiqHashStruct)
Object.const_get(item.evm_object_class)
else
item.class.base_class
end
node = @ems_xml_nodes[klass_name][item.id]
$log.error("#{log_header} Resource <#{klass_name}_#{item.id} - #{item.name}> not found in cached resource tree.") if node.nil?
node
end
Expand Down Expand Up @@ -957,7 +961,8 @@ def ems_metadata_tree_add_hosts_under_clusters!(result)

def convert_to_xml(xml, result)
result.each do |obj, children|
@ems_xml_nodes["#{obj.class.base_class}_#{obj.id}"] = node = xml.add_element(obj.class.base_class.name, :object => ci_to_hash_struct(obj))
@ems_xml_nodes[obj.class.base_class] ||= {}
@ems_xml_nodes[obj.class.base_class][obj.id] = node = xml.add_element(obj.class.base_class.name, :object => ci_to_hash_struct(obj))
convert_to_xml(node, children)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/miq_request_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
ems_folder.ext_management_system = ems
attrs = ems_folder.attributes.merge(:object => ems_folder)
xml_hash = XmlHash::Element.new('EmsFolder', attrs)
hash = {"ResourcePool_#{resource_pool.id}" => xml_hash}
hash = { ResourcePool => { resource_pool.id => xml_hash } }
workflow.instance_variable_set("@ems_xml_nodes", hash)
end

Expand All @@ -486,7 +486,7 @@
ems_folder.ext_management_system = ems
attrs = resource_pool.attributes.merge(:object => resource_pool, :ems => ems)
xml_hash = XmlHash::Element.new('ResourcePool', attrs)
hash = {"EmsFolder_#{ems_folder.id}" => xml_hash}
hash = { EmsFolder => { ems_folder.id => xml_hash } }
workflow.instance_variable_set("@ems_xml_nodes", hash)
end

Expand All @@ -506,7 +506,7 @@
datacenter.ext_management_system = ems
attrs = datacenter.attributes.merge(:object => datacenter, :ems => ems)
xml_hash = XmlHash::Element.new('EmsFolder', attrs)
hash = {"EmsFolder_#{datacenter.id}" => xml_hash}
hash = { EmsFolder => { datacenter.id => xml_hash } }
workflow.instance_variable_set("@ems_xml_nodes", hash)
end

Expand Down

0 comments on commit ef73d6e

Please sign in to comment.