Commit 08107941 authored by Erick Bajao's avatar Erick Bajao

Use insert_all

parent 2430c28f
...@@ -6,7 +6,7 @@ class BackfillProjectsWithCoverage < ActiveRecord::Migration[6.1] ...@@ -6,7 +6,7 @@ class BackfillProjectsWithCoverage < ActiveRecord::Migration[6.1]
MIGRATION = 'BackfillProjectsWithCoverage' MIGRATION = 'BackfillProjectsWithCoverage'
DELAY_INTERVAL = 2.minutes DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 10_000 BATCH_SIZE = 10_000
SUB_BATCH_SIZE = 100 SUB_BATCH_SIZE = 1_000
disable_ddl_transaction! disable_ddl_transaction!
......
...@@ -4,6 +4,10 @@ module Gitlab ...@@ -4,6 +4,10 @@ module Gitlab
module BackgroundMigration module BackgroundMigration
# Backfill project_ci_feature_usages for a range of projects with coverage # Backfill project_ci_feature_usages for a range of projects with coverage
class BackfillProjectsWithCoverage class BackfillProjectsWithCoverage
class ProjectCiFeatureUsage < ActiveRecord::Base # rubocop:disable Style/Documentation
self.table_name = 'project_ci_feature_usages'
end
COVERAGE_ENUM_VALUE = 1 COVERAGE_ENUM_VALUE = 1
INSERT_DELAY_SECONDS = 0.1 INSERT_DELAY_SECONDS = 0.1
...@@ -15,11 +19,7 @@ module Gitlab ...@@ -15,11 +19,7 @@ module Gitlab
SQL SQL
report_results.to_a.in_groups_of(sub_batch_size, false) do |batch| report_results.to_a.in_groups_of(sub_batch_size, false) do |batch|
ActiveRecord::Base.connection.execute <<~SQL ProjectCiFeatureUsage.insert_all(build_values(batch))
INSERT INTO project_ci_feature_usages (project_id, feature, default_branch) VALUES
#{build_values(batch)}
ON CONFLICT (project_id, feature, default_branch) DO NOTHING;
SQL
sleep INSERT_DELAY_SECONDS sleep INSERT_DELAY_SECONDS
end end
...@@ -29,8 +29,12 @@ module Gitlab ...@@ -29,8 +29,12 @@ module Gitlab
def build_values(batch) def build_values(batch)
batch.map do |data| batch.map do |data|
"(#{data['project_id']}, #{COVERAGE_ENUM_VALUE}, #{data['default_branch']})" {
end.join(', ') project_id: data['project_id'],
feature: COVERAGE_ENUM_VALUE,
default_branch: data['default_branch']
}
end
end end
end end
end end
......
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