fixed all issues - not doing bulk create.

This commit is contained in:
James Lopez 2017-05-05 10:43:56 +02:00
parent 1fe8b7f646
commit adcff298f8
2 changed files with 15 additions and 7 deletions

View File

@ -21,16 +21,12 @@ module Projects
private
def propagate_projects_with_template
offset = 0
loop do
batch = project_ids_batch(offset)
batch = project_ids_batch
bulk_create_from_template(batch)
break if batch.size < BATCH_SIZE
offset += BATCH_SIZE
end
end
@ -44,7 +40,7 @@ module Projects
end
end
def project_ids_batch(offset)
def project_ids_batch
Project.connection.execute(
<<-SQL
SELECT id
@ -55,7 +51,7 @@ module Projects
WHERE services.project_id = projects.id
AND services.type = '#{@template.type}'
)
LIMIT #{BATCH_SIZE} OFFSET #{offset}
LIMIT #{BATCH_SIZE}
SQL
).to_a.flatten
end

View File

@ -66,5 +66,17 @@ describe Projects::PropagateService, services: true do
expect(service.properties).to eq(service_template.properties)
end
describe 'bulk update' do
it 'creates services for all projects' do
project_total = 5
stub_const 'Projects::PropagateService::BATCH_SIZE', 3
project_total.times { create(:empty_project) }
expect { described_class.propagate(service_template) }.
to change { Service.count }.by(project_total + 1)
end
end
end
end