Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
08107941
Commit
08107941
authored
Sep 02, 2021
by
Erick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use insert_all
parent
2430c28f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
db/post_migrate/20210818185845_backfill_projects_with_coverage.rb
...migrate/20210818185845_backfill_projects_with_coverage.rb
+1
-1
lib/gitlab/background_migration/backfill_projects_with_coverage.rb
...b/background_migration/backfill_projects_with_coverage.rb
+11
-7
No files found.
db/post_migrate/20210818185845_backfill_projects_with_coverage.rb
View file @
08107941
...
...
@@ -6,7 +6,7 @@ class BackfillProjectsWithCoverage < ActiveRecord::Migration[6.1]
MIGRATION
=
'BackfillProjectsWithCoverage'
DELAY_INTERVAL
=
2
.
minutes
BATCH_SIZE
=
10_000
SUB_BATCH_SIZE
=
100
SUB_BATCH_SIZE
=
1
_0
00
disable_ddl_transaction!
...
...
lib/gitlab/background_migration/backfill_projects_with_coverage.rb
View file @
08107941
...
...
@@ -4,6 +4,10 @@ module Gitlab
module
BackgroundMigration
# Backfill project_ci_feature_usages for a range of projects with coverage
class
BackfillProjectsWithCoverage
class
ProjectCiFeatureUsage
<
ActiveRecord
::
Base
# rubocop:disable Style/Documentation
self
.
table_name
=
'project_ci_feature_usages'
end
COVERAGE_ENUM_VALUE
=
1
INSERT_DELAY_SECONDS
=
0.1
...
...
@@ -15,11 +19,7 @@ module Gitlab
SQL
report_results
.
to_a
.
in_groups_of
(
sub_batch_size
,
false
)
do
|
batch
|
ActiveRecord
::
Base
.
connection
.
execute
<<~
SQL
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
ProjectCiFeatureUsage
.
insert_all
(
build_values
(
batch
))
sleep
INSERT_DELAY_SECONDS
end
...
...
@@ -29,8 +29,12 @@ module Gitlab
def
build_values
(
batch
)
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment