diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2018-02-06 18:32:34 +0300 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2018-02-07 19:02:34 +0300 |
commit | cf25ef38d2e58a46c4a09e4bc416618afd676c78 (patch) | |
tree | 76d15a72fc2874b6f48c8c2af70ddf522f979cf0 /lib/gitlab | |
parent | 9ab4c5b735e0e121996b092cb20bcdc423045c5e (diff) |
Cache Gitaly FindCommit RPC response
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 |