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
38921267
Commit
38921267
authored
Mar 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
55f209ad
a7cf6135
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
70 additions
and
14 deletions
+70
-14
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+3
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+14
-12
changelogs/unreleased/sh-fix-gitaly-find-commit-caching.yml
changelogs/unreleased/sh-fix-gitaly-find-commit-caching.yml
+5
-0
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+20
-0
lib/gitlab/gitaly_client/commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+1
-1
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+4
-0
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+15
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+8
-0
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
38921267
...
...
@@ -315,7 +315,9 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
end
def
serializer
MergeRequestSerializer
.
new
(
current_user:
current_user
,
project:
merge_request
.
project
)
::
Gitlab
::
GitalyClient
.
allow_ref_name_caching
do
MergeRequestSerializer
.
new
(
current_user:
current_user
,
project:
merge_request
.
project
)
end
end
def
define_edit_vars
...
...
app/models/ci/pipeline.rb
View file @
38921267
...
...
@@ -465,9 +465,9 @@ module Ci
end
def
latest?
return
false
unless
ref
&&
commit
.
present?
return
false
unless
git_
ref
&&
commit
.
present?
project
.
commit
(
ref
)
==
commit
project
.
commit
(
git_
ref
)
==
commit
end
def
retried
...
...
@@ -781,16 +781,18 @@ module Ci
end
def
git_ref
if
merge_request_event?
##
# In the future, we're going to change this ref to
# merge request's merged reference, such as "refs/merge-requests/:iid/merge".
# In order to do that, we have to update GitLab-Runner's source pulling
# logic.
# See https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/1092
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
.
to_s
else
super
strong_memoize
(
:git_ref
)
do
if
merge_request_event?
##
# In the future, we're going to change this ref to
# merge request's merged reference, such as "refs/merge-requests/:iid/merge".
# In order to do that, we have to update GitLab-Runner's source pulling
# logic.
# See https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/1092
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
.
to_s
else
super
end
end
end
...
...
changelogs/unreleased/sh-fix-gitaly-find-commit-caching.yml
0 → 100644
View file @
38921267
---
title
:
Allow ref name caching CommitService#find_commit
merge_request
:
26248
author
:
type
:
performance
lib/gitlab/gitaly_client.rb
View file @
38921267
...
...
@@ -302,6 +302,26 @@ module Gitlab
end
end
# Normally a FindCommit RPC will cache the commit with its SHA
# instead of a ref name, since it's possible the branch is mutated
# afterwards. However, for read-only requests that never mutate the
# branch, this method allows caching of the ref name directly.
def
self
.
allow_ref_name_caching
return
yield
unless
Gitlab
::
SafeRequestStore
.
active?
return
yield
if
ref_name_caching_allowed?
begin
Gitlab
::
SafeRequestStore
[
:allow_ref_name_caching
]
=
true
yield
ensure
Gitlab
::
SafeRequestStore
[
:allow_ref_name_caching
]
=
false
end
end
def
self
.
ref_name_caching_allowed?
Gitlab
::
SafeRequestStore
[
:allow_ref_name_caching
]
end
def
self
.
get_call_count
(
key
)
Gitlab
::
SafeRequestStore
[
key
]
||
0
end
...
...
lib/gitlab/gitaly_client/commit_service.rb
View file @
38921267
...
...
@@ -286,7 +286,7 @@ module Gitlab
commit
=
call_find_commit
(
revision
)
return
unless
commit
key
[
:commit_id
]
=
commit
.
id
key
[
:commit_id
]
=
commit
.
id
unless
GitalyClient
.
ref_name_caching_allowed?
Gitlab
::
SafeRequestStore
[
key
]
=
commit
else
call_find_commit
(
revision
)
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
38921267
...
...
@@ -86,6 +86,10 @@ describe Projects::MergeRequestsController do
end
describe
'as json'
do
before
do
expect
(
::
Gitlab
::
GitalyClient
).
to
receive
(
:allow_ref_name_caching
).
and_call_original
end
context
'with basic serializer param'
do
it
'renders basic MR entity as json'
do
go
(
serializer:
'basic'
,
format: :json
)
...
...
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
View file @
38921267
...
...
@@ -221,6 +221,21 @@ describe Gitlab::GitalyClient::CommitService do
expect
(
commit
).
to
eq
(
commit_dbl
)
end
end
context
'when caching of the ref name is enabled'
do
it
'returns a cached commit'
do
expect_any_instance_of
(
Gitaly
::
CommitService
::
Stub
).
to
receive
(
:find_commit
).
once
.
and_return
(
double
(
commit:
commit_dbl
))
commit
=
nil
2
.
times
do
::
Gitlab
::
GitalyClient
.
allow_ref_name_caching
do
commit
=
described_class
.
new
(
repository
).
find_commit
(
'master'
)
end
end
expect
(
commit
).
to
eq
(
commit_dbl
)
end
end
end
end
...
...
spec/models/ci/pipeline_spec.rb
View file @
38921267
...
...
@@ -1469,6 +1469,14 @@ describe Ci::Pipeline, :mailer do
end
end
context
'with a branch name as the ref'
do
it
'looks up commit with the full ref name'
do
expect
(
pipeline
.
project
).
to
receive
(
:commit
).
with
(
'refs/heads/master'
).
and_call_original
expect
(
pipeline
).
to
be_latest
end
end
context
'with not latest sha'
do
before
do
pipeline
.
update
(
...
...
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