summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-12-22 13:22:07 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2016-12-22 13:22:07 +0000
commita1aa0d7829445400053157e6dae4c610c494cb52 (patch)
tree931e97385ce83fefbb366d20b725731557c58b67 /app/models
parent6e2a6fd09167947a3bd8e1a4cda96dbfae395b3a (diff)
parent1a59766d0c7ed78a7167040af512842979d2414e (diff)
downloadgitlab-ce-a1aa0d7829445400053157e6dae4c610c494cb52.tar.gz
Merge branch 'cache-last-commit-sha-for-path' into 'master'
Cache last commit id for path See merge request !8098
Diffstat (limited to 'app/models')
-rw-r--r--app/models/repository.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 1ccabdb7c1f..3266e9c75f0 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -654,11 +654,19 @@ 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 = last_commit_id_for_path(sha, path)
commit(sha)
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
+ args = %W(#{Gitlab.config.git.bin_path} rev-list --max-count=1 #{sha} -- #{path})
+ Gitlab::Popen.popen(args, path_to_repo).first.strip
+ end
+ end
+
def next_branch(name, opts = {})
branch_ids = self.branch_names.map do |n|
next 1 if n == name