diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-29 13:31:57 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-29 13:31:57 +0300 |
commit | a7cf61355a45a67ef404eeec3e38738f997ef2ec (patch) | |
tree | f64b6940e63c2f88a431f24a0cf890614578444e /lib | |
parent | fea9400ec8a2a31d582a425226494f5fb9f90495 (diff) | |
parent | 7a2325e43c1fe726b4affc544449a763fb52b9e7 (diff) |
Merge branch 'sh-fix-gitaly-find-commit-caching' into 'master'
Allow ref name caching CommitService#find_commit
Closes #57083
See merge request gitlab-org/gitlab-ce!26248
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/commit_service.rb | 2 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 49cff7517e9..f240387c28c 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -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 diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb index ea12424eb4a..0d5debfcd01 100644 --- a/lib/gitlab/gitaly_client/commit_service.rb +++ b/lib/gitlab/gitaly_client/commit_service.rb @@ -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) |