Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/admin/propagate_integration_service.rb')
-rw-r--r--app/services/admin/propagate_integration_service.rb88
1 files changed, 19 insertions, 69 deletions
diff --git a/app/services/admin/propagate_integration_service.rb b/app/services/admin/propagate_integration_service.rb
index 9a5ce58ee2c..34d6008cb6a 100644
--- a/app/services/admin/propagate_integration_service.rb
+++ b/app/services/admin/propagate_integration_service.rb
@@ -2,46 +2,24 @@
module Admin
class PropagateIntegrationService
- BATCH_SIZE = 100
-
- delegate :data_fields_present?, to: :integration
-
- def self.propagate(integration:, overwrite:)
- new(integration, overwrite).propagate
- end
-
- def initialize(integration, overwrite)
- @integration = integration
- @overwrite = overwrite
- end
+ include PropagateService
def propagate
- if overwrite
- update_integration_for_all_projects
- else
- update_integration_for_inherited_projects
- end
+ update_inherited_integrations
+ create_integration_for_groups_without_integration if Feature.enabled?(:group_level_integrations)
create_integration_for_projects_without_integration
end
private
- attr_reader :integration, :overwrite
-
# rubocop: disable Cop/InBatches
# rubocop: disable CodeReuse/ActiveRecord
- def update_integration_for_inherited_projects
+ def update_inherited_integrations
Service.where(type: integration.type, inherit_from_id: integration.id).in_batches(of: BATCH_SIZE) do |batch|
bulk_update_from_integration(batch)
end
end
-
- def update_integration_for_all_projects
- Service.where(type: integration.type).in_batches(of: BATCH_SIZE) do |batch|
- bulk_update_from_integration(batch)
- end
- end
# rubocop: enable Cop/InBatches
# rubocop: enable CodeReuse/ActiveRecord
@@ -62,61 +40,33 @@ module Admin
end
# rubocop: enable CodeReuse/ActiveRecord
- def create_integration_for_projects_without_integration
+ def create_integration_for_groups_without_integration
loop do
- batch = Project.uncached { Project.ids_without_integration(integration, BATCH_SIZE) }
+ batch = Group.uncached { group_ids_without_integration(integration, BATCH_SIZE) }
- bulk_create_from_integration(batch) unless batch.empty?
+ bulk_create_from_integration(batch, 'group') unless batch.empty?
break if batch.size < BATCH_SIZE
end
end
- def bulk_create_from_integration(batch)
- service_list = ServiceList.new(batch, service_hash, { 'inherit_from_id' => integration.id }).to_array
-
- Project.transaction do
- results = bulk_insert(*service_list)
-
- if data_fields_present?
- data_list = DataList.new(results, data_fields_hash, integration.data_fields.class).to_array
-
- bulk_insert(*data_list)
- end
-
- run_callbacks(batch)
- end
- end
-
- def bulk_insert(klass, columns, values_array)
- items_to_insert = values_array.map { |array| Hash[columns.zip(array)] }
-
- klass.insert_all(items_to_insert, returning: [:id])
- end
-
- # rubocop: disable CodeReuse/ActiveRecord
- def run_callbacks(batch)
- if integration.issue_tracker?
- Project.where(id: batch).update_all(has_external_issue_tracker: true)
- end
-
- if active_external_wiki?
- Project.where(id: batch).update_all(has_external_wiki: true)
- end
- end
- # rubocop: enable CodeReuse/ActiveRecord
-
- def active_external_wiki?
- integration.type == 'ExternalWikiService'
- end
-
def service_hash
@service_hash ||= integration.to_service_hash
.tap { |json| json['inherit_from_id'] = integration.id }
end
- def data_fields_hash
- @data_fields_hash ||= integration.to_data_fields_hash
+ # rubocop:disable CodeReuse/ActiveRecord
+ def group_ids_without_integration(integration, limit)
+ services = Service
+ .select('1')
+ .where('services.group_id = namespaces.id')
+ .where(type: integration.type)
+
+ Group
+ .where('NOT EXISTS (?)', services)
+ .limit(limit)
+ .pluck(:id)
end
+ # rubocop:enable CodeReuse/ActiveRecord
end
end