From 0f7ed33759a2d995043beaf6ed99dd6bdac62dc2 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 7 Mar 2019 17:19:56 -0800 Subject: Cache Repository#root_ref within a request When an empty project is loaded in the UI, there are 15 separate Gitaly FindDefaultBranch calls to determine the root_ref. Previously, it was not cached even within the request. This change caches it within the request so only a single FindDefaultBranch RPC is needed. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/58684 --- app/models/repository.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'app/models/repository.rb') diff --git a/app/models/repository.rb b/app/models/repository.rb index 851175a61b7..285fce1e6dd 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -534,10 +534,9 @@ class Repository end def root_ref - # When the repo does not exist, or there is no root ref, we raise this error so no data is cached. - raw_repository&.root_ref or raise Gitlab::Git::Repository::NoRepository # rubocop:disable Style/AndOr + raw_repository&.root_ref end - cache_method :root_ref + cache_method_asymmetrically :root_ref # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/314 def exists? -- cgit v1.2.1