BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
fb89f417
Commit
fb89f417
authored
Feb 07, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/cache-gitaly-find-commits' into 'master'
Cache Gitaly FindCommit RPC response See merge request gitlab-org/gitlab-ce!16949
parents
714d8e95
cf25ef38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
8 deletions
+56
-8
commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+30
-8
commit_service_spec.rb
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+26
-0
No files found.
lib/gitlab/gitaly_client/commit_service.rb
View file @
fb89f417
...
...
@@ -222,14 +222,25 @@ module Gitlab
end
def
find_commit
(
revision
)
request
=
Gitaly
::
FindCommitRequest
.
new
(
repository:
@gitaly_repo
,
revision:
encode_binary
(
revision
)
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:find_commit
,
request
,
timeout:
GitalyClient
.
medium_timeout
)
response
.
commit
if
RequestStore
.
active?
# We don't use RequeStstore.fetch(key) { ... } directly because `revision`
# can be a branch name, so we can't use it as a key as it could point
# to another commit later on (happens a lot in tests).
key
=
{
storage:
@gitaly_repo
.
storage_name
,
relative_path:
@gitaly_repo
.
relative_path
,
commit_id:
revision
}
return
RequestStore
[
key
]
if
RequestStore
.
exist?
(
key
)
commit
=
call_find_commit
(
revision
)
return
unless
commit
key
[
:commit_id
]
=
commit
.
id
RequestStore
[
key
]
=
commit
else
call_find_commit
(
revision
)
end
end
def
patch
(
revision
)
...
...
@@ -346,6 +357,17 @@ module Gitlab
def
encode_repeated
(
a
)
Google
::
Protobuf
::
RepeatedField
.
new
(
:bytes
,
a
.
map
{
|
s
|
encode_binary
(
s
)
}
)
end
def
call_find_commit
(
revision
)
request
=
Gitaly
::
FindCommitRequest
.
new
(
repository:
@gitaly_repo
,
revision:
encode_binary
(
revision
)
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:find_commit
,
request
,
timeout:
GitalyClient
.
medium_timeout
)
response
.
commit
end
end
end
end
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
View file @
fb89f417
...
...
@@ -166,6 +166,32 @@ describe Gitlab::GitalyClient::CommitService do
described_class
.
new
(
repository
).
find_commit
(
revision
)
end
describe
'caching'
,
:request_store
do
let
(
:commit_dbl
)
{
double
(
id:
'f01b'
*
10
)
}
context
'when passed revision is a branch name'
do
it
'calls Gitaly'
do
expect_any_instance_of
(
Gitaly
::
CommitService
::
Stub
).
to
receive
(
:find_commit
).
twice
.
and_return
(
double
(
commit:
commit_dbl
))
commit
=
nil
2
.
times
{
commit
=
described_class
.
new
(
repository
).
find_commit
(
'master'
)
}
expect
(
commit
).
to
eq
(
commit_dbl
)
end
end
context
'when passed revision is a commit ID'
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
{
commit
=
described_class
.
new
(
repository
).
find_commit
(
'f01b'
*
10
)
}
expect
(
commit
).
to
eq
(
commit_dbl
)
end
end
end
end
describe
'#patch'
do
...
...
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