Commit da5f72c1 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

HgGitRepository: avoid calling Gitaly for each SHA conversion

Spotted by the rate limit on Gitaly calls. We're simply caching
the result if it's positive.

--HG--
branch : heptapod-stable
parent 49c095c70b60
......@@ -278,14 +278,24 @@ def git_sha_map
@git_sha_map ||= hg_sha_map.to_a.map {|x| x.reverse }.to_h
end
# Useful for repetitive calls, and will cache only the `true` result
# Rationale: repetitive calls are typically for existing repositories.
# (disabling the cop because that's really what we want, and there's
# another cop preventing us to use a more explicit style)
# rubocop:disable Gitlab/PredicateMemoization
def cached_exists?
@cache_exists ||= exists?
end
# rubocop:enable Gitlab/PredicateMemoization
def sha_from_hgsha(hgsha)
return unless exists?
return unless cached_exists?
git_sha_map[hgsha]
end
def hgsha_from_sha(sha)
return unless exists?
return unless cached_exists?
hg_sha_map[sha]
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment