blob: a4290eb86bfdc7c9ae22c7479e5b1e062fb94d4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# frozen_string_literal: true
module BulkImports
module Uniquify
private
def uniquify(namespace, data_item, data_type)
return data_item unless namespace.present?
children_items = Set.new
# index_namespaces_on_parent_id_and_id index supports this
Namespace.by_parent(namespace).each_batch do |relation|
children_items.merge(relation.pluck(data_type).to_set) # rubocop: disable CodeReuse/ActiveRecord
end
return data_item unless children_items.include?(data_item)
data_item = Gitlab::Utils::Uniquify.new(1).string(->(counter) { "#{data_item}_#{counter}" }) do |base|
children_items.include?(base)
end
end
end
end
|