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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
bc365bd1
Commit
bc365bd1
authored
Mar 06, 2018
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use persisted/memoized value for MRs shas instead of doing git lookups
parent
49f72d06
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
10 deletions
+27
-10
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
app/models/environment.rb
app/models/environment.rb
+2
-2
app/models/merge_request.rb
app/models/merge_request.rb
+16
-4
changelogs/unreleased/mr-commit-optimization.yml
changelogs/unreleased/mr-commit-optimization.yml
+5
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+3
-3
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
bc365bd1
...
@@ -187,7 +187,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
...
@@ -187,7 +187,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
begin
begin
@merge_request
.
environments_for
(
current_user
).
map
do
|
environment
|
@merge_request
.
environments_for
(
current_user
).
map
do
|
environment
|
project
=
environment
.
project
project
=
environment
.
project
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_
commit
)
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_
sha
)
stop_url
=
stop_url
=
if
environment
.
stop_action?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
if
environment
.
stop_action?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
...
...
app/models/environment.rb
View file @
bc365bd1
...
@@ -99,8 +99,8 @@ class Environment < ActiveRecord::Base
...
@@ -99,8 +99,8 @@ class Environment < ActiveRecord::Base
folder_name
==
"production"
folder_name
==
"production"
end
end
def
first_deployment_for
(
commit
)
def
first_deployment_for
(
commit
_sha
)
ref
=
project
.
repository
.
ref_name_for_sha
(
ref_path
,
commit
.
sha
)
ref
=
project
.
repository
.
ref_name_for_sha
(
ref_path
,
commit
_
sha
)
return
nil
unless
ref
return
nil
unless
ref
...
...
app/models/merge_request.rb
View file @
bc365bd1
...
@@ -375,15 +375,27 @@ class MergeRequest < ActiveRecord::Base
...
@@ -375,15 +375,27 @@ class MergeRequest < ActiveRecord::Base
end
end
def
diff_start_sha
def
diff_start_sha
diff_start_commit
.
try
(
:sha
)
if
persisted?
merge_request_diff
.
start_commit_sha
else
target_branch_head
.
try
(
:sha
)
end
end
end
def
diff_base_sha
def
diff_base_sha
diff_base_commit
.
try
(
:sha
)
if
persisted?
merge_request_diff
.
base_commit_sha
else
branch_merge_base_commit
.
try
(
:sha
)
end
end
end
def
diff_head_sha
def
diff_head_sha
diff_head_commit
.
try
(
:sha
)
if
persisted?
merge_request_diff
.
head_commit_sha
else
source_branch_head
.
try
(
:sha
)
end
end
end
# When importing a pull request from GitHub, the old and new branches may no
# When importing a pull request from GitHub, the old and new branches may no
...
@@ -646,7 +658,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -646,7 +658,7 @@ class MergeRequest < ActiveRecord::Base
!
ProtectedBranch
.
protected?
(
source_project
,
source_branch
)
&&
!
ProtectedBranch
.
protected?
(
source_project
,
source_branch
)
&&
!
source_project
.
root_ref?
(
source_branch
)
&&
!
source_project
.
root_ref?
(
source_branch
)
&&
Ability
.
allowed?
(
current_user
,
:
push_code
,
source_project
)
&&
Ability
.
allowed?
(
current_user
,
:
push_code
,
source_project
)
&&
diff_head_
commit
==
source_branch_head
diff_head_
sha
==
source_branch_head
.
try
(:
sha
)
end
end
def
should_remove_source_branch?
def
should_remove_source_branch?
...
...
changelogs/unreleased/mr-commit-optimization.yml
0 → 100644
View file @
bc365bd1
---
title
:
Use persisted/memoized value for MRs shas instead of doing git lookups
merge_request
:
17555
author
:
type
:
performance
spec/models/environment_spec.rb
View file @
bc365bd1
...
@@ -142,15 +142,15 @@ describe Environment do
...
@@ -142,15 +142,15 @@ describe Environment do
let
(
:commit
)
{
project
.
commit
.
parent
}
let
(
:commit
)
{
project
.
commit
.
parent
}
it
'returns deployment id for the environment'
do
it
'returns deployment id for the environment'
do
expect
(
environment
.
first_deployment_for
(
commit
)).
to
eq
deployment1
expect
(
environment
.
first_deployment_for
(
commit
.
id
)).
to
eq
deployment1
end
end
it
'return nil when no deployment is found'
do
it
'return nil when no deployment is found'
do
expect
(
environment
.
first_deployment_for
(
head_commit
)).
to
eq
nil
expect
(
environment
.
first_deployment_for
(
head_commit
.
id
)).
to
eq
nil
end
end
it
'returns a UTF-8 ref'
do
it
'returns a UTF-8 ref'
do
expect
(
environment
.
first_deployment_for
(
commit
).
ref
).
to
be_utf8
expect
(
environment
.
first_deployment_for
(
commit
.
id
).
ref
).
to
be_utf8
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