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

Refactor get_ems_folders to create less strings #17358

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
12 changes: 9 additions & 3 deletions app/models/miq_request_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -856,19 +856,25 @@ def ems_has_clusters?
end

def get_ems_folders(folder, dh = {}, full_path = "")
path = full_path
if folder.evm_object_class == :EmsFolder
if folder.hidden
return dh if folder.name != 'vm'
else
full_path += full_path.blank? ? folder.name.to_s : " / #{folder.name}"
dh[folder.id] = full_path unless folder.type == "Datacenter"
path = full_path.dup
if path.blank?
path << folder.name.to_s
else
path << " / ".freeze << folder.name
end
dh[folder.id] = path unless folder.type == "Datacenter".freeze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to have `elseif folder.type != "Datacenter".freeze ?
(not sure if you want to pull out into a const)

Copy link
Member Author

@NickLaMuro NickLaMuro May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not sure if you want to pull out into a const)

Per @syncrou 's previous review, he thought it was easier to read when it was not a constant. I already had it as a constant originally.

would it make sense to have `elseif folder.type != "Datacenter".freeze ?

Possibly, though I was mostly trying to keep the logic the same, and just adjusting things to limit object allocations. If you look at the previous code, the if logic is basically exactly the same, I just expanded out the ternary operator since I thought it was easier to read in that form. Figured trying to tweak the logic would add unneeded risk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah - you are actually using path below

end
end

# Process child folders
@_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?
node.children.each { |child| get_ems_folders(child.attributes[:object], dh, path) } unless node.nil?

dh
end
Expand Down