Commit 896857eb authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'propagate-integrations' into 'master'

Follow-up propagate integrations service

See merge request gitlab-org/gitlab!32748
parents 7b3b88dd db923d39
...@@ -16,7 +16,7 @@ module IntegrationsActions ...@@ -16,7 +16,7 @@ module IntegrationsActions
def update def update
saved = integration.update(service_params[:service]) saved = integration.update(service_params[:service])
overwrite = ActiveRecord::Type::Boolean.new.cast(params[:overwrite]) overwrite = Gitlab::Utils.to_boolean(params[:overwrite])
respond_to do |format| respond_to do |format|
format.html do format.html do
......
...@@ -114,23 +114,21 @@ module Admin ...@@ -114,23 +114,21 @@ module Admin
integration.type == 'ExternalWikiService' integration.type == 'ExternalWikiService'
end end
# rubocop: disable CodeReuse/ActiveRecord
def project_ids_without_integration def project_ids_without_integration
Project.connection.select_values( services = Service
<<-SQL .select('1')
SELECT id .where('services.project_id = projects.id')
FROM projects .where(type: integration.type)
WHERE NOT EXISTS (
SELECT true Project
FROM services .where('NOT EXISTS (?)', services)
WHERE services.project_id = projects.id .where(pending_delete: false)
AND services.type = #{ActiveRecord::Base.connection.quote(integration.type)} .where(archived: false)
) .limit(BATCH_SIZE)
AND projects.pending_delete = false .pluck(:id)
AND projects.archived = false
LIMIT #{BATCH_SIZE}
SQL
)
end end
# rubocop: enable CodeReuse/ActiveRecord
def service_hash def service_hash
@service_hash ||= integration.to_service_hash @service_hash ||= integration.to_service_hash
......
...@@ -26,7 +26,7 @@ module Projects ...@@ -26,7 +26,7 @@ module Projects
def propagate_projects_with_template def propagate_projects_with_template
loop do loop do
batch = Project.uncached { project_ids_batch } batch = Project.uncached { project_ids_without_integration }
bulk_create_from_template(batch) unless batch.empty? bulk_create_from_template(batch) unless batch.empty?
...@@ -50,23 +50,21 @@ module Projects ...@@ -50,23 +50,21 @@ module Projects
end end
end end
def project_ids_batch # rubocop: disable CodeReuse/ActiveRecord
Project.connection.select_values( def project_ids_without_integration
<<-SQL services = Service
SELECT id .select('1')
FROM projects .where('services.project_id = projects.id')
WHERE NOT EXISTS ( .where(type: template.type)
SELECT true
FROM services Project
WHERE services.project_id = projects.id .where('NOT EXISTS (?)', services)
AND services.type = #{ActiveRecord::Base.connection.quote(template.type)} .where(pending_delete: false)
) .where(archived: false)
AND projects.pending_delete = false .limit(BATCH_SIZE)
AND projects.archived = false .pluck(:id)
LIMIT #{BATCH_SIZE}
SQL
)
end end
# rubocop: enable CodeReuse/ActiveRecord
def bulk_insert(klass, columns, values_array) def bulk_insert(klass, columns, values_array)
items_to_insert = values_array.map { |array| Hash[columns.zip(array)] } items_to_insert = values_array.map { |array| Hash[columns.zip(array)] }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment