Commit 4e93cb9c authored by Hiroyuki Sato's avatar Hiroyuki Sato

Cache last commit sha for path

parent c1dbae90
......@@ -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
......
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