From fb49c94e49149a2043b774ba33daa3fe79febdd4 Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Thu, 24 Aug 2017 09:20:04 +0000 Subject: Delegate Repository::branch_exists? and ref_exists? to Gitlab::Git --- app/models/repository.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/models/repository.rb b/app/models/repository.rb index c1e4fcf94a4..cb2cf658084 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -206,12 +206,18 @@ class Repository end def branch_exists?(branch_name) - branch_names.include?(branch_name) + return false unless raw_repository + + @branch_exists_memo ||= Hash.new do |hash, key| + hash[key] = raw_repository.branch_exists?(key) + end + + @branch_exists_memo[branch_name] end def ref_exists?(ref) - rugged.references.exist?(ref) - rescue Rugged::ReferenceError + !!raw_repository&.ref_exists?(ref) + rescue ArgumentError false end @@ -266,6 +272,7 @@ class Repository def expire_branches_cache expire_method_caches(%i(branch_names branch_count)) @local_branches = nil + @branch_exists_memo = nil end def expire_statistics_caches -- cgit v1.2.1