diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-07 22:20:45 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-07 22:20:45 +0300 |
commit | fb89f41721edecc1408ab20d1c0cfe5bb1a00a94 (patch) | |
tree | af0fe99ff268093b9ee9ca755616a5f437d085a5 /lib/gitlab | |
parent | 714d8e95f6de31ed2686f1b2ca05cb5d1f68c878 (diff) | |
parent | cf25ef38d2e58a46c4a09e4bc416618afd676c78 (diff) |
Merge branch 'fix/cache-gitaly-find-commits' into 'master'
Cache Gitaly FindCommit RPC response
See merge request gitlab-org/gitlab-ce!16949
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/gitaly_client/commit_service.rb | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb index 5767f06b0ce..269a048cf5d 100644 --- a/lib/gitlab/gitaly_client/commit_service.rb +++ b/lib/gitlab/gitaly_client/commit_service.rb @@ -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 |