summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/repository.rb22
-rw-r--r--app/services/git_push_service.rb4
3 files changed, 25 insertions, 3 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 043f08b9a13..f11c6d7c6be 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -790,6 +790,8 @@ class Project < ActiveRecord::Base
def change_head(branch)
# Cached divergent commit counts are based on repository head
repository.expire_branch_cache
+ repository.expire_root_ref_cache
+
gitlab_shell.update_repository_head(self.path_with_namespace, branch)
reload_default_branch
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index e813c946bc1..27bdbac3e52 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -44,7 +44,9 @@ class Repository
end
def empty?
- raw_repository.empty?
+ return @empty unless @empty.nil?
+
+ @empty = cache.fetch(:empty?) { raw_repository.empty? }
end
#
@@ -57,7 +59,11 @@ class Repository
# This method return true if repository contains some content visible in project page.
#
def has_visible_content?
- raw_repository.branch_count > 0
+ return @has_visible_content unless @has_visible_content.nil?
+
+ @has_visible_content = cache.fetch(:has_visible_content?) do
+ raw_repository.branch_count > 0
+ end
end
def commit(id = 'HEAD')
@@ -243,6 +249,16 @@ class Repository
end
end
+ def expire_root_ref_cache
+ cache.expire(:root_ref)
+ @root_ref = nil
+ end
+
+ def expire_has_visible_content_cache
+ cache.expire(:has_visible_content?)
+ @has_visible_content = nil
+ end
+
def rebuild_cache
cache_keys.each do |key|
cache.expire(key)
@@ -480,7 +496,7 @@ class Repository
end
def root_ref
- @root_ref ||= raw_repository.root_ref
+ @root_ref ||= cache.fetch(:root_ref) { raw_repository.root_ref }
end
def commit_dir(user, path, message, branch)
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb
index d7ea30bc315..0f31756797d 100644
--- a/app/services/git_push_service.rb
+++ b/app/services/git_push_service.rb
@@ -21,8 +21,12 @@ class GitPushService
project.repository.expire_cache
if push_remove_branch?(ref, newrev)
+ project.repository.expire_has_visible_content_cache
+
@push_commits = []
elsif push_to_new_branch?(ref, oldrev)
+ project.repository.expire_has_visible_content_cache
+
# Re-find the pushed commits.
if is_default_branch?(ref)
# Initial push to the default branch. Take the full history of that branch as "newly pushed".