summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2017-09-14 13:50:58 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2017-09-14 13:50:58 +0000
commita0c9ed3a22e5654c03606f95e1331665fae2cbd2 (patch)
treefafa0121328dcec6bfdc7a59c23dda812dc94fde
parent1140fcce4f8b5463f451356b76fea125826478b2 (diff)
parent0657002251a48e39849204b6eed8e633bee32563 (diff)
downloadgitlab-ce-a0c9ed3a22e5654c03606f95e1331665fae2cbd2.tar.gz
Merge branch 'repo-cache-fix' into 'master'
Restore has_visible_content? to improve performance (cache) See merge request gitlab-org/gitlab-ce!14264
-rw-r--r--app/models/repository.rb6
-rw-r--r--spec/workers/git_garbage_collect_worker_spec.rb4
2 files changed, 8 insertions, 2 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 035f85a0b46..6ed33e0c268 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -90,6 +90,12 @@ class Repository
)
end
+ # we need to have this method here because it is not cached in ::Git and
+ # the method is called multiple times for every request
+ def has_visible_content?
+ branch_count > 0
+ end
+
def inspect
"#<#{self.class.name}:#{@disk_path}>"
end
diff --git a/spec/workers/git_garbage_collect_worker_spec.rb b/spec/workers/git_garbage_collect_worker_spec.rb
index 6f9ddb6c63c..f7b67b8efc6 100644
--- a/spec/workers/git_garbage_collect_worker_spec.rb
+++ b/spec/workers/git_garbage_collect_worker_spec.rb
@@ -31,8 +31,8 @@ describe GitGarbageCollectWorker do
expect_any_instance_of(Repository).to receive(:after_create_branch).and_call_original
expect_any_instance_of(Repository).to receive(:branch_names).and_call_original
+ expect_any_instance_of(Repository).to receive(:has_visible_content?).and_call_original
expect_any_instance_of(Gitlab::Git::Repository).to receive(:branch_count).and_call_original
- expect_any_instance_of(Gitlab::Git::Repository).to receive(:has_visible_content?).and_call_original
subject.perform(project.id, :gc, lease_key, lease_uuid)
end
@@ -77,8 +77,8 @@ describe GitGarbageCollectWorker do
expect_any_instance_of(Repository).to receive(:after_create_branch).and_call_original
expect_any_instance_of(Repository).to receive(:branch_names).and_call_original
+ expect_any_instance_of(Repository).to receive(:has_visible_content?).and_call_original
expect_any_instance_of(Gitlab::Git::Repository).to receive(:branch_count).and_call_original
- expect_any_instance_of(Gitlab::Git::Repository).to receive(:has_visible_content?).and_call_original
subject.perform(project.id)
end