Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add uniq on datacenters in #host_to_folder
The more stripped down version of this method, prior to the change, is as follows: def host_to_folder(src) sources = src[:host].nil? ? allowed_hosts_obj : [src[:host]] datacenters = sources.collect { |h| find_datacenter_for_ci(h) end.compact datacenters.each_with_object({}) do |dc, folders| folders.merge!(get_ems_folders(dc)) end end The `find_datacenter_for_ci` method basically looks up the datacenter for the matching host object in the xml tree that has been generated. In most (all) cases though, their will be more than one host per datacenter, and that wasn't taken into account for this method since the next block blindly takes those datacenters and merges the folder structure it gets from `get_ems_folders` for each datacenter. By adding a `.uniq` prior to the assignment of datacenters, this saves a significant number of unnecessary CPU cycles and object allocations to fetch the same data and apply it to the `folders` variable, without changing the end result. Note: Ideally we would want a better algorithm for finding the datacenters for a collection of hosts, one that allowed for ejecting early from find_datacenter_for_ci when we knew an existing datacenter for a given host had already been found. But the time taken to get the datacenters from the hosts is far less in CPU time than the time taken to call `#get_ems_folders` per datacenter object and merge the hash with the existing results.
- Loading branch information