提交 08f5ea05 编写于 作者: L Lin Jen-Shin

Merge branch 'pl-flat_map-ce' into 'master'

Prefer `flat_map` over `map` + `flatten`

See merge request gitlab-org/gitlab-ce!31144
......@@ -47,7 +47,7 @@ module ProtectedRef
def access_levels_for_ref(ref, action:, protected_refs: nil)
self.matching(ref, protected_refs: protected_refs)
.map(&:"#{action}_access_levels").flatten
.flat_map(&:"#{action}_access_levels")
end
# Returns all protected refs that match the given ref name.
......
......@@ -388,7 +388,7 @@ class Group < Namespace
variables = Ci::GroupVariable.where(group: list_of_ids)
variables = variables.unprotected unless project.protected_for?(ref)
variables = variables.group_by(&:group_id)
list_of_ids.reverse.map { |group| variables[group.id] }.compact.flatten
list_of_ids.reverse.flat_map { |group| variables[group.id] }.compact
end
def group_member(user)
......
......@@ -59,14 +59,14 @@ class StageEntity < Grape::Entity
end
def latest_statuses
HasStatus::ORDERED_STATUSES.map do |ordered_status|
HasStatus::ORDERED_STATUSES.flat_map do |ordered_status|
grouped_statuses.fetch(ordered_status, [])
end.flatten
end
end
def retried_statuses
HasStatus::ORDERED_STATUSES.map do |ordered_status|
HasStatus::ORDERED_STATUSES.flat_map do |ordered_status|
grouped_retried_statuses.fetch(ordered_status, [])
end.flatten
end
end
end
......@@ -10,13 +10,13 @@ module Ci
update_retried
new_builds =
stage_indexes_of_created_processables.map do |index|
stage_indexes_of_created_processables.flat_map do |index|
process_stage(index)
end
@pipeline.update_status
new_builds.flatten.any?
new_builds.any?
end
private
......
......@@ -10,7 +10,7 @@ module API
when String
value.split(',').map(&:strip)
when Array
value.map { |v| v.to_s.split(',').map(&:strip) }.flatten
value.flat_map { |v| v.to_s.split(',').map(&:strip) }
when LabelsList
value
else
......
......@@ -33,7 +33,7 @@ module Banzai
#
# data - An Array of a Hashes mapping an HTML document to nodes to redact.
def redact_document_nodes(all_document_nodes)
all_nodes = all_document_nodes.map { |x| x[:nodes] }.flatten
all_nodes = all_document_nodes.flat_map { |x| x[:nodes] }
visible = nodes_visible_to_user(all_nodes)
metadata = []
......
......@@ -40,7 +40,7 @@ module Gitlab
end
def reload!
@shards = Hash[*Shard.all.map { |shard| [shard.name, shard.id] }.flatten]
@shards = Hash[*Shard.all.flat_map { |shard| [shard.name, shard.id] }]
end
end
......
......@@ -46,7 +46,7 @@ module Gitlab
parallelized_job_names = @parallelized_jobs.keys.map(&:to_s)
parallelized_config.each_with_object({}) do |(job_name, config), hash|
if config[:dependencies] && (intersection = config[:dependencies] & parallelized_job_names).any?
parallelized_deps = intersection.map { |dep| @parallelized_jobs[dep.to_sym].map(&:first) }.flatten
parallelized_deps = intersection.flat_map { |dep| @parallelized_jobs[dep.to_sym].map(&:first) }
deps = config[:dependencies] - intersection + parallelized_deps
hash[job_name] = config.merge(dependencies: deps)
else
......
......@@ -34,11 +34,9 @@ module Gitlab
def extended_statuses
return @extended_statuses if defined?(@extended_statuses)
groups = self.class.extended_statuses.map do |group|
@extended_statuses = self.class.extended_statuses.flat_map do |group|
Array(group).find { |status| status.matches?(@subject, @user) }
end
@extended_statuses = groups.flatten.compact
end.compact
end
def self.extended_statuses
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册