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
dd6cb07f
Commit
dd6cb07f
authored
Nov 03, 2018
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-11-03
parents
51679f61
4d3ff28a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
5 deletions
+73
-5
app/models/merge_request.rb
app/models/merge_request.rb
+9
-0
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+6
-0
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+6
-5
changelogs/unreleased/sh-optimize-mr-commit-sha-lookup.yml
changelogs/unreleased/sh-optimize-mr-commit-sha-lookup.yml
+5
-0
spec/models/merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+21
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+26
-0
No files found.
app/models/merge_request.rb
View file @
dd6cb07f
...
@@ -355,6 +355,15 @@ class MergeRequest < ActiveRecord::Base
...
@@ -355,6 +355,15 @@ class MergeRequest < ActiveRecord::Base
end
end
end
end
# Returns true if there are commits that match at least one commit SHA.
def
includes_any_commits?
(
shas
)
if
persisted?
merge_request_diff
.
commits_by_shas
(
shas
).
exists?
else
(
commit_shas
&
shas
).
present?
end
end
# Calls `MergeWorker` to proceed with the merge process and
# Calls `MergeWorker` to proceed with the merge process and
# updates `merge_jid` with the MergeWorker#jid.
# updates `merge_jid` with the MergeWorker#jid.
# This helps tracking enqueued and ongoing merge jobs.
# This helps tracking enqueued and ongoing merge jobs.
...
...
app/models/merge_request_diff.rb
View file @
dd6cb07f
...
@@ -140,6 +140,12 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -140,6 +140,12 @@ class MergeRequestDiff < ActiveRecord::Base
merge_request_diff_commits
.
map
(
&
:sha
)
merge_request_diff_commits
.
map
(
&
:sha
)
end
end
def
commits_by_shas
(
shas
)
return
[]
unless
shas
.
present?
merge_request_diff_commits
.
where
(
sha:
shas
)
end
def
diff_refs
=
(
new_diff_refs
)
def
diff_refs
=
(
new_diff_refs
)
self
.
base_commit_sha
=
new_diff_refs
&
.
base_sha
self
.
base_commit_sha
=
new_diff_refs
&
.
base_sha
self
.
start_commit_sha
=
new_diff_refs
&
.
start_sha
self
.
start_commit_sha
=
new_diff_refs
&
.
start_sha
...
...
app/services/merge_requests/refresh_service.rb
View file @
dd6cb07f
...
@@ -89,11 +89,8 @@ module MergeRequests
...
@@ -89,11 +89,8 @@ module MergeRequests
filter_merge_requests
(
merge_requests
).
each
do
|
merge_request
|
filter_merge_requests
(
merge_requests
).
each
do
|
merge_request
|
if
branch_and_project_match?
(
merge_request
)
||
@push
.
force_push?
if
branch_and_project_match?
(
merge_request
)
||
@push
.
force_push?
merge_request
.
reload_diff
(
current_user
)
merge_request
.
reload_diff
(
current_user
)
else
elsif
merge_request
.
includes_any_commits?
(
push_commit_ids
)
mr_commit_ids
=
merge_request
.
commit_shas
merge_request
.
reload_diff
(
current_user
)
push_commit_ids
=
@commits
.
map
(
&
:id
)
matches
=
mr_commit_ids
&
push_commit_ids
merge_request
.
reload_diff
(
current_user
)
if
matches
.
any?
end
end
merge_request
.
mark_as_unchecked
merge_request
.
mark_as_unchecked
...
@@ -106,6 +103,10 @@ module MergeRequests
...
@@ -106,6 +103,10 @@ module MergeRequests
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
def
push_commit_ids
@push_commit_ids
||=
@commits
.
map
(
&
:id
)
end
def
branch_and_project_match?
(
merge_request
)
def
branch_and_project_match?
(
merge_request
)
merge_request
.
source_project
==
@project
&&
merge_request
.
source_project
==
@project
&&
merge_request
.
source_branch
==
@push
.
branch_name
merge_request
.
source_branch
==
@push
.
branch_name
...
...
changelogs/unreleased/sh-optimize-mr-commit-sha-lookup.yml
0 → 100644
View file @
dd6cb07f
---
title
:
Optimize merge request refresh by using the database to check commit SHAs
merge_request
:
22731
author
:
type
:
performance
spec/models/merge_request_diff_spec.rb
View file @
dd6cb07f
...
@@ -211,4 +211,25 @@ describe MergeRequestDiff do
...
@@ -211,4 +211,25 @@ describe MergeRequestDiff do
expect
(
diff_with_commits
.
commits_count
).
to
eq
(
29
)
expect
(
diff_with_commits
.
commits_count
).
to
eq
(
29
)
end
end
end
end
describe
'#commits_by_shas'
do
let
(
:commit_shas
)
{
diff_with_commits
.
commit_shas
}
it
'returns empty if no SHAs were provided'
do
expect
(
diff_with_commits
.
commits_by_shas
([])).
to
be_empty
end
it
'returns one SHA'
do
commits
=
diff_with_commits
.
commits_by_shas
([
commit_shas
.
first
,
Gitlab
::
Git
::
BLANK_SHA
])
expect
(
commits
.
count
).
to
eq
(
1
)
end
it
'returns all matching SHAs'
do
commits
=
diff_with_commits
.
commits_by_shas
(
commit_shas
)
expect
(
commits
.
count
).
to
eq
(
commit_shas
.
count
)
expect
(
commits
.
map
(
&
:sha
)).
to
match_array
(
commit_shas
)
end
end
end
end
spec/models/merge_request_spec.rb
View file @
dd6cb07f
...
@@ -3040,6 +3040,32 @@ describe MergeRequest do
...
@@ -3040,6 +3040,32 @@ describe MergeRequest do
end
end
end
end
describe
'#includes_any_commits?'
do
it
'returns false'
do
expect
(
subject
.
includes_any_commits?
([
Gitlab
::
Git
::
BLANK_SHA
])).
to
be_falsey
end
it
'returns true'
do
expect
(
subject
.
includes_any_commits?
([
subject
.
merge_request_diff
.
head_commit_sha
])).
to
be_truthy
end
it
'returns true even when there is a non-existent comit'
do
expect
(
subject
.
includes_any_commits?
([
Gitlab
::
Git
::
BLANK_SHA
,
subject
.
merge_request_diff
.
head_commit_sha
])).
to
be_truthy
end
context
'unpersisted merge request'
do
let
(
:new_mr
)
{
build
(
:merge_request
)
}
it
'returns false'
do
expect
(
new_mr
.
includes_any_commits?
([
Gitlab
::
Git
::
BLANK_SHA
])).
to
be_falsey
end
it
'returns true'
do
expect
(
new_mr
.
includes_any_commits?
([
subject
.
merge_request_diff
.
head_commit_sha
])).
to
be_truthy
end
end
end
describe
'#can_allow_collaboration?'
do
describe
'#can_allow_collaboration?'
do
let
(
:target_project
)
{
create
(
:project
,
:public
)
}
let
(
:target_project
)
{
create
(
:project
,
:public
)
}
let
(
:source_project
)
{
fork_project
(
target_project
)
}
let
(
:source_project
)
{
fork_project
(
target_project
)
}
...
...
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