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
6315d2fd
Commit
6315d2fd
authored
Jan 31, 2019
by
Mark Chao
Committed by
Bob Van Landuyt
Feb 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only check project rules with MR rule matching condition
Cuts time by not iterating through each project rule.
parent
03d8971a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
9 deletions
+12
-9
ee/db/migrate/20190114040404_correct_approvals_required.rb
ee/db/migrate/20190114040404_correct_approvals_required.rb
+12
-9
No files found.
ee/db/migrate/20190114040404_correct_approvals_required.rb
View file @
6315d2fd
...
...
@@ -18,18 +18,21 @@ class CorrectApprovalsRequired < ActiveRecord::Migration[5.0]
end
def
up
ApprovalProjectRule
.
find_each
do
|
project_rule
|
project_rule_ids
=
ApprovalMergeRequestRule
.
joins
(
:approval_project_rule
)
.
where
(
'approval_merge_request_rules.approvals_required = 0 AND approval_project_rules.approvals_required > 0'
)
.
pluck
(
'approval_project_rules.id'
)
ApprovalProjectRule
.
where
(
id:
project_rule_ids
).
find_each
do
|
project_rule
|
# rubocop:disable GitlabSecurity/SqlInjection
target_mr_rules
=
ApprovalMergeRequestRule
.
joins
(
:approval_project_rule
)
.
where
(
"approval_merge_request_rules.approvals_required = 0 AND approval_project_rules.id =
#{
project_rule
.
id
}
AND approval_project_rules.approvals_required > 0"
)
.
select
(
'approval_merge_request_rules.id'
)
# Pluck as MySQL prohibits subquery that references the table being updated
mr_rule_ids
=
ApprovalMergeRequestRule
.
joins
(
:approval_merge_request_rule_source
)
.
where
(
"approval_merge_request_rules.approvals_required = 0 AND approval_merge_request_rule_sources.approval_project_rule_id =
#{
project_rule
.
id
}
"
)
.
pluck
(
'approval_merge_request_rules.id'
)
# rubocop:enable GitlabSecurity/SqlInjection
# MySQL prohibits subquery that references the table being updated
target_mr_rules
=
target_mr_rules
.
pluck
(
:id
)
ApprovalMergeRequestRule
.
where
(
id:
target_mr_rules
).
update_all
(
approvals_required:
project_rule
.
approvals_required
)
ApprovalMergeRequestRule
.
where
(
id:
mr_rule_ids
).
update_all
(
approvals_required:
project_rule
.
approvals_required
)
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