summaryrefslogtreecommitdiff
path: root/app/models/repository.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-01-05 15:44:22 +0000
committerDouwe Maan <douwe@gitlab.com>2016-01-05 15:44:22 +0000
commit07c39c9976bcceca94b11525917cd27db8088b2f (patch)
tree332c4bb637056e04cb54edfa75396e2a347b098b /app/models/repository.rb
parent7c3c901ada6fc4a6d2d3ce7a2cf8188cf6615008 (diff)
parent2e8ec7e7204b2876218db34439584204b1062265 (diff)
downloadgitlab-ce-07c39c9976bcceca94b11525917cd27db8088b2f.tar.gz
Merge branch 'brunsa2/gitlab-ce-diverging-branch-graphs' into 'master'
Add graphs of commits ahead/behind default branch (by @brunsa2) Replaces https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/1716 See merge request !2301
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r--app/models/repository.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index a9bf4eb4033..6ecd2d2f27e 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -175,11 +175,29 @@ class Repository
def size
cache.fetch(:size) { raw_repository.size }
end
+
+ def diverging_commit_counts(branch)
+ root_ref_hash = raw_repository.rev_parse_target(root_ref).oid
+ cache.fetch(:"diverging_commit_counts_#{branch.name}") do
+ # Rugged seems to throw a `ReferenceError` when given branch_names rather
+ # than SHA-1 hashes
+ number_commits_behind = commits_between(branch.target, root_ref_hash).size
+ number_commits_ahead = commits_between(root_ref_hash, branch.target).size
+
+ { behind: number_commits_behind, ahead: number_commits_ahead }
+ end
+ end
def cache_keys
%i(size branch_names tag_names commit_count
readme version contribution_guide changelog license)
end
+
+ def branch_cache_keys
+ branches.map do |branch|
+ :"diverging_commit_counts_#{branch.name}"
+ end
+ end
def build_cache
cache_keys.each do |key|
@@ -187,6 +205,12 @@ class Repository
send(key)
end
end
+
+ branches.each do |branch|
+ unless cache.exist?(:"diverging_commit_counts_#{branch.name}")
+ send(:diverging_commit_counts, branch)
+ end
+ end
end
def expire_tags_cache
@@ -203,6 +227,14 @@ class Repository
cache_keys.each do |key|
cache.expire(key)
end
+
+ expire_branch_cache
+ end
+
+ def expire_branch_cache
+ branches.each do |branch|
+ cache.expire(:"diverging_commit_counts_#{branch.name}")
+ end
end
def rebuild_cache
@@ -210,6 +242,11 @@ class Repository
cache.expire(key)
send(key)
end
+
+ branches.each do |branch|
+ cache.expire(:"diverging_commit_counts_#{branch.name}")
+ diverging_commit_counts(branch)
+ end
end
def lookup_cache