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
Boxiang Sun
gitlab-ce
Commits
cf25ef38
Commit
cf25ef38
authored
Feb 06, 2018
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache Gitaly FindCommit RPC response
parent
9ab4c5b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
8 deletions
+56
-8
lib/gitlab/gitaly_client/commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+30
-8
spec/lib/gitlab/gitaly_client/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 @
cf25ef38
...
@@ -222,14 +222,25 @@ module Gitlab
...
@@ -222,14 +222,25 @@ module Gitlab
end
end
def
find_commit
(
revision
)
def
find_commit
(
revision
)
request
=
Gitaly
::
FindCommitRequest
.
new
(
if
RequestStore
.
active?
repository:
@gitaly_repo
,
# We don't use RequeStstore.fetch(key) { ... } directly because `revision`
revision:
encode_binary
(
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
=
{
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:find_commit
,
request
,
timeout:
GitalyClient
.
medium_timeout
)
storage:
@gitaly_repo
.
storage_name
,
relative_path:
@gitaly_repo
.
relative_path
,
response
.
commit
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
end
def
patch
(
revision
)
def
patch
(
revision
)
...
@@ -346,6 +357,17 @@ module Gitlab
...
@@ -346,6 +357,17 @@ module Gitlab
def
encode_repeated
(
a
)
def
encode_repeated
(
a
)
Google
::
Protobuf
::
RepeatedField
.
new
(
:bytes
,
a
.
map
{
|
s
|
encode_binary
(
s
)
}
)
Google
::
Protobuf
::
RepeatedField
.
new
(
:bytes
,
a
.
map
{
|
s
|
encode_binary
(
s
)
}
)
end
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
end
end
end
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
View file @
cf25ef38
...
@@ -166,6 +166,32 @@ describe Gitlab::GitalyClient::CommitService do
...
@@ -166,6 +166,32 @@ describe Gitlab::GitalyClient::CommitService do
described_class
.
new
(
repository
).
find_commit
(
revision
)
described_class
.
new
(
repository
).
find_commit
(
revision
)
end
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
end
describe
'#patch'
do
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