diff options
author | Robert Speicher <robert@gitlab.com> | 2018-03-07 17:53:16 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-03-07 17:53:16 +0000 |
commit | 3da9cb692911aa4463f92307f66d823f0ea61625 (patch) | |
tree | 1edcdf1bf4948c692d2fc7d77986bf6cec647f4d | |
parent | 87e163137cdfcaf7b0aab110dc776e7629402214 (diff) | |
parent | 37162a5fa64c79f5f05868b4f3a6b8b4776b0182 (diff) | |
download | gitlab-ce-3da9cb692911aa4463f92307f66d823f0ea61625.tar.gz |
Merge branch 'fix/reduce-number-of-find-commit-for-log-tree' into 'master'
Reduce number of FindCommit calls from RefsController#logs_tree
Closes gitaly#1057
See merge request gitlab-org/gitlab-ce!17566
-rw-r--r-- | app/models/repository.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 8 |
2 files changed, 7 insertions, 6 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index e6b88320110..461dfbec2bc 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -651,14 +651,15 @@ class Repository end 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 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)}" cache.fetch(key) do - raw_repository.last_commit_id_for_path(sha, path) + last_commit_for_path(sha, path)&.id end end diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 1445b7924dc..d4f6b543daf 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1443,12 +1443,12 @@ module Gitlab 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| if is_enabled - last_commit_for_path_by_gitaly(sha, path).id + last_commit_for_path_by_gitaly(sha, path) else - last_commit_id_for_path_by_shelling_out(sha, path) + last_commit_for_path_by_rugged(sha, path) end end end @@ -1896,7 +1896,7 @@ module Gitlab end 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) end |