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 60aaf40
Showing 1 changed file with 8 additions and 3 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

0 comments on commit 60aaf40

Please sign in to comment.