From 0689663487c66d21aa83da0830bc2c042f89e6e8 Mon Sep 17 00:00:00 2001
From: Yorick Peterse <yorickpeterse@gmail.com>
Date: Thu, 21 Jan 2016 18:19:18 +0100
Subject: [PATCH] Use branch_count in Repository#has_visible_content?

Gitlab::Git::Repository#branch_count is a tad faster than the previous
setup. See gitlab-org/gitlab_git!62 for more information.
---
 app/models/repository.rb       |  2 +-
 spec/models/repository_spec.rb | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/app/models/repository.rb b/app/models/repository.rb
index d9ff71c01ed..f89a3890a49 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -57,7 +57,7 @@ class Repository
   # This method return true if repository contains some content visible in project page.
   #
   def has_visible_content?
-    !raw_repository.branches.empty?
+    raw_repository.branch_count > 0
   end
 
   def commit(id = 'HEAD')
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index afbf62035ac..c484ae8fc8c 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -219,4 +219,24 @@ describe Repository, models: true do
       end
     end
   end
+
+  describe '#has_visible_content?' do
+    subject { repository.has_visible_content? }
+
+    describe 'when there are no branches' do
+      before do
+        allow(repository.raw_repository).to receive(:branch_count).and_return(0)
+      end
+
+      it { is_expected.to eq(false) }
+    end
+
+    describe 'when there are branches' do
+      before do
+        allow(repository.raw_repository).to receive(:branch_count).and_return(3)
+      end
+
+      it { is_expected.to eq(true) }
+    end
+  end
 end
-- 
GitLab