Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize _log.prefix calls #17355

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions app/models/miq_request_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,8 @@ def find_respools_under_ci(item)
def find_classes_under_ci(item, klass)
results = []
return results if item.nil?
node = load_ems_node(item, _log.prefix)
@_find_classes_under_ci_prefix ||= _log.prefix
node = load_ems_node(item, @_find_classes_under_ci_prefix)
each_ems_metadata(node.attributes[:object], klass) { |ci| results << ci } unless node.nil?
results
end
Expand Down Expand Up @@ -865,7 +866,8 @@ def get_ems_folders(folder, dh = {}, full_path = "")
end

# Process child folders
node = load_ems_node(folder, _log.prefix)
@_get_ems_folders_prefix ||= _log.prefix
node = load_ems_node(folder, @_get_ems_folders_prefix)
node.children.each { |child| get_ems_folders(child.attributes[:object], dh, full_path) } unless node.nil?

dh
Expand Down Expand Up @@ -905,7 +907,8 @@ def find_cluster_above_ci(item, ems_src = nil)

def find_class_above_ci(item, klass, _ems_src = nil, datacenter = false)
result = nil
node = load_ems_node(item, _log.prefix)
@_find_class_above_ci_prefix ||= _log.prefix
node = load_ems_node(item, @_find_class_above_ci_prefix)
klass_name = klass.name.to_sym
# Walk the xml document parents to find the requested class
while node.kind_of?(XmlHash::Element)
Expand All @@ -926,7 +929,8 @@ def each_ems_metadata(ems_ci = nil, klass = nil, &_blk)
ems_xml = get_ems_metadata_tree(src)
ems_node = ems_xml.try(:root)
else
ems_node = load_ems_node(ems_ci, _log.prefix)
@_each_ems_metadata_prefix ||= _log.prefix
ems_node = load_ems_node(ems_ci, @_each_ems_metadata_prefix)
end
klass_name = klass.name.to_sym unless klass.nil?
unless ems_node.nil?
Expand Down Expand Up @@ -1030,7 +1034,8 @@ def allowed_hosts_obj(options = {})
hosts_ids = find_all_ems_of_type(Host).collect(&:id)
hosts_ids &= load_ar_obj(src[:storage]).hosts.collect(&:id) unless src[:storage].nil?
if datacenter
dc_node = load_ems_node(datacenter, _log.prefix)
@_allowed_hosts_obj_prefix ||= _log.prefix
dc_node = load_ems_node(datacenter, @_allowed_hosts_obj_prefix)
hosts_ids &= find_hosts_under_ci(dc_node.attributes[:object]).collect(&:id)
end
return [] if hosts_ids.blank?
Expand Down