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

Follow up on #54 "Fog google upgrade (to 1.3.3)" code cleanup #59

Merged
merged 1 commit into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ def get_zones
def get_flavors
# Google API returns a duplicate flavor for every zone
# so build a unique list of flavors using the flavor
flavors = @connection.list_aggregated_machine_types.items.values.each_with_object([]) do |zone, arr|
arr.concat(zone.machine_types) if zone.machine_types
end
flavors.uniq!(&:id)
flavors_by_zone = @connection.list_aggregated_machine_types.items
flavors = flavors_by_zone.values.flat_map(&:machine_types).compact.uniq(&:id)

process_collection(flavors, :flavors) { |flavor| parse_flavor(flavor) }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def get_cloud_networks

def subnetworks
unless @subnetworks
@subnetworks = @connection.list_aggregated_subnetworks.to_h[:items].flat_map { |_, v| v[:subnetworks] }
@subnetworks = @connection.list_aggregated_subnetworks.to_h[:items].values.flat_map { |v| v[:subnetworks] }
Copy link
Member Author

Choose a reason for hiding this comment

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

@agrare, I couldn't do here what you've suggested. The :subnetworks is not an method but a key in Hash so we can't be calling it like:

@connection.list_aggregated_subnetworks.to_h[:items].values.flat_map(&:subnetworks)

I've tried also this:

@connection.list_aggregated_subnetworks.to_h[:items].values.pluck(:subnetworks).flatten

Despite it's being a bit better readable, it performs about twice slower than the flat_map version (due to the flatten). So I've left the flat_map here.

Copy link
Member

Choose a reason for hiding this comment

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

👍 it was the .values instead of { |_, v| that I most cared about

# For a backwards compatibility, old GCE networks were created without subnet. It's not possible now, but
# GCE haven't migrated to new format. We will create a fake subnet for each network without subnets.
@subnetworks += @connection.networks.select { |x| x.ipv4_range.present? }.map do |x|
Expand Down