diff options
author | Hiroyuki Sato <h-sato@ruby-dev.jp> | 2016-12-15 13:29:51 +0900 |
---|---|---|
committer | Hiroyuki Sato <h-sato@ruby-dev.jp> | 2016-12-20 18:24:24 +0900 |
commit | 4e93cb9c2f89387c02bc59e8fdf0d5a93c516f7a (patch) | |
tree | f4baf2ff50617fa830b912d3493a810a76c9e485 | |
parent | c1dbae90033c10bef1aaa3c5c34219c1d0e5ef61 (diff) | |
download | gitlab-ce-4e93cb9c2f89387c02bc59e8fdf0d5a93c516f7a.tar.gz |
Cache last commit sha for path
-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 |