diff options
-rw-r--r-- | app/models/repository.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 1ccabdb7c1f..bedb3be88c5 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -654,11 +654,22 @@ class Repository end def last_commit_for_path(sha, path) - args = %W(#{Gitlab.config.git.bin_path} rev-list --max-count=1 #{sha} -- #{path}) - sha = Gitlab::Popen.popen(args, path_to_repo).first.strip + sha = cache_last_commit_sha_for_path(sha, path) commit(sha) end + def last_commit_sha_for_path(sha, path) + args = %W(#{Gitlab.config.git.bin_path} rev-list --max-count=1 #{sha} -- #{path}) + Gitlab::Popen.popen(args, path_to_repo).first.strip + end + + def cache_last_commit_sha_for_path(sha, path) + key = path.blank? ? "last_commit_sha_for_path:#{sha}" : "last_commit_id_for_path:#{sha}:#{Digest::SHA1.hexdigest(path)}" + cache.fetch(key) do + last_commit_sha_for_path(sha, path) + end + end + def next_branch(name, opts = {}) branch_ids = self.branch_names.map do |n| next 1 if n == name |