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/gitlab/gitaly_client.rb | |
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/gitlab/gitaly_client.rb')
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 20 |
1 files changed, 20 insertions, 0 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 |