Reduce number of FindCommit calls from RefsController#logs_tree
Fixes gitaly#1057 The old code was calling LastCommitForPath to extract a commit ID _then_ call FindCommit to get a commit it already had in the first place!
This commit is contained in:
parent
5e8138aa54
commit
37162a5fa6
|
@ -651,14 +651,15 @@ class Repository
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_commit_for_path(sha, path)
|
def last_commit_for_path(sha, path)
|
||||||
commit_by(oid: last_commit_id_for_path(sha, path))
|
commit = raw_repository.last_commit_for_path(sha, path)
|
||||||
|
::Commit.new(commit, @project) if commit
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_commit_id_for_path(sha, path)
|
def last_commit_id_for_path(sha, path)
|
||||||
key = path.blank? ? "last_commit_id_for_path:#{sha}" : "last_commit_id_for_path:#{sha}:#{Digest::SHA1.hexdigest(path)}"
|
key = path.blank? ? "last_commit_id_for_path:#{sha}" : "last_commit_id_for_path:#{sha}:#{Digest::SHA1.hexdigest(path)}"
|
||||||
|
|
||||||
cache.fetch(key) do
|
cache.fetch(key) do
|
||||||
raw_repository.last_commit_id_for_path(sha, path)
|
last_commit_for_path(sha, path)&.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1443,12 +1443,12 @@ module Gitlab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_commit_id_for_path(sha, path)
|
def last_commit_for_path(sha, path)
|
||||||
gitaly_migrate(:last_commit_for_path) do |is_enabled|
|
gitaly_migrate(:last_commit_for_path) do |is_enabled|
|
||||||
if is_enabled
|
if is_enabled
|
||||||
last_commit_for_path_by_gitaly(sha, path).id
|
last_commit_for_path_by_gitaly(sha, path)
|
||||||
else
|
else
|
||||||
last_commit_id_for_path_by_shelling_out(sha, path)
|
last_commit_for_path_by_rugged(sha, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1896,7 +1896,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_commit_for_path_by_rugged(sha, path)
|
def last_commit_for_path_by_rugged(sha, path)
|
||||||
sha = last_commit_id_for_path(sha, path)
|
sha = last_commit_id_for_path_by_shelling_out(sha, path)
|
||||||
commit(sha)
|
commit(sha)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue