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
c290f143
Commit
c290f143
authored
Oct 13, 2021
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `each_batch` to prevent running unnecessary queries
parent
d857c53f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
ee/lib/ee/gitlab/background_migration/populate_status_column_of_security_scans.rb
...und_migration/populate_status_column_of_security_scans.rb
+12
-4
No files found.
ee/lib/ee/gitlab/background_migration/populate_status_column_of_security_scans.rb
View file @
c290f143
...
...
@@ -23,11 +23,19 @@ module EE
security_scans.id BETWEEN %<start_id>d AND %<end_id>d
SQL
class
SecurityScan
<
ActiveRecord
::
Base
include
EachBatch
scope
:in_range
,
->
(
start_id
,
end_id
)
{
where
(
id:
(
start_id
..
end_id
))
}
end
def
perform
(
start_id
,
end_id
)
log_info
(
'Migration has been started'
,
start_id:
start_id
,
end_id:
end_id
)
(
start_id
..
end_id
).
step
(
UPDATE_BATCH_SIZE
).
each
do
|
batch_start
|
update_batch
(
batch_start
)
SecurityScan
.
in_range
(
start_id
,
end_id
).
each_batch
(
of:
UPDATE_BATCH_SIZE
)
do
|
relation
|
batch_start
,
batch_end
=
relation
.
pluck
(
"MIN(id), MAX(id)"
).
first
update_batch
(
batch_start
,
batch_end
)
end
log_info
(
'Migration has been finished'
,
start_id:
start_id
,
end_id:
end_id
)
...
...
@@ -38,8 +46,8 @@ module EE
delegate
:connection
,
to:
ActiveRecord
::
Base
,
private:
true
delegate
:execute
,
:quote
,
to: :connection
,
private:
true
def
update_batch
(
batch_start
)
sql
=
format
(
UPDATE_SQL
,
start_id:
quote
(
batch_start
),
end_id:
quote
(
batch_
start
+
UPDATE_BATCH_SIZE
-
1
))
def
update_batch
(
batch_start
,
batch_end
)
sql
=
format
(
UPDATE_SQL
,
start_id:
quote
(
batch_start
),
end_id:
quote
(
batch_
end
))
result
=
::
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/340017'
)
do
execute
(
sql
)
...
...
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