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
0e186a05
Commit
0e186a05
authored
Jan 06, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid query and model initialization
Finding id is enough for update
parent
fb7c62b8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules.rb
...ackground_migration/migrate_approver_to_approval_rules.rb
+13
-13
No files found.
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules.rb
View file @
0e186a05
...
...
@@ -19,8 +19,6 @@ module Gitlab
class
ApprovalMergeRequestRule
<
ActiveRecord
::
Base
self
.
table_name
=
'approval_merge_request_rules'
include
Gitlab
::
Utils
::
StrongMemoize
belongs_to
:merge_request
scope
:code_owner
,
->
{
where
(
code_owner:
true
)
}
scope
:regular
,
->
{
where
(
code_owner:
false
)
}
# Non code owner rule
...
...
@@ -57,15 +55,17 @@ module Gitlab
belongs_to
:target_project
,
class_name:
"Project"
has_many
:approval_rules
,
class_name:
'ApprovalMergeRequestRule'
def
approvers
Approver
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
)
def
approver
_id
s
@approver_ids
||=
Approver
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
).
pluck
(
:user_
id
)
end
def
approver_groups
ApproverGroup
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
)
def
approver_group
_id
s
@approver_group_ids
||=
ApproverGroup
.
where
(
target_type:
'MergeRequest'
,
target_id:
id
).
pluck
(
:group_
id
)
end
def
sync_code_owners_with_approvers
return
if
state
==
'merged'
||
state
==
'closed'
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
::
MergeRequest
.
find
(
id
).
sync_code_owners_with_approvers
end
...
...
@@ -77,12 +77,12 @@ module Gitlab
has_many
:approval_rules
,
class_name:
'ApprovalProjectRule'
def
approvers
Approver
.
where
(
target_type:
'Project'
,
target_id:
id
)
def
approver
_id
s
@approver_ids
||=
Approver
.
where
(
target_type:
'Project'
,
target_id:
id
).
pluck
(
:user_
id
)
end
def
approver_groups
ApproverGroup
.
where
(
target_type:
'Project'
,
target_id:
id
)
def
approver_group
_id
s
@approver_group_ids
||=
ApproverGroup
.
where
(
target_type:
'Project'
,
target_id:
id
).
pluck
(
:group_
id
)
end
end
...
...
@@ -131,8 +131,8 @@ module Gitlab
end
rule
=
find_or_create_rule
rule
.
user_ids
=
target
.
approver
s
.
pluck
(
:user_id
)
rule
.
group_ids
=
target
.
approver_group
s
.
pluck
(
:group_id
)
rule
.
user_ids
=
target
.
approver
_ids
rule
.
group_ids
=
target
.
approver_group
_ids
rule
end
...
...
@@ -159,7 +159,7 @@ module Gitlab
end
def
approvers_exists?
target
.
approver
s
.
to_a
.
any?
||
target
.
approver_groups
.
to_a
.
any?
target
.
approver
_ids
.
any?
||
target
.
approver_group_ids
.
any?
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