diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-11-08 18:42:13 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-11-21 12:51:40 +0100 |
commit | 6f393877e555c9e87017747cd70d3577bb70a03e (patch) | |
tree | 8c73554988332d33550f788bc69c951c3f8c3e5e /app | |
parent | df5548e19e8c988b709e66a7e35ddc097344913e (diff) | |
download | gitlab-ce-6f393877e555c9e87017747cd70d3577bb70a03e.tar.gz |
Use File.exist? to check if a repository exists
Initializing Rugged objects is way too expensive just to check if a
repository exists. Even though we cache this data once in a while we
have to refresh this. On GitLab.com we have seen Repository#exists?
taking up to _1 minute_ to complete in the absolute worst case, though
usually it sits around a second or so.
Using File.exist? to instead check if $GIT_DIR/refs exists is a much
faster way of checking if a repository was initialized properly.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/repository.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 06c9eb3bd70..bd5dd7e8f74 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -41,11 +41,7 @@ class Repository return @exists unless @exists.nil? @exists = cache.fetch(:exists?) do - begin - raw_repository && raw_repository.rugged ? true : false - rescue Gitlab::Git::Repository::NoRepository - false - end + refs_directory_exists? end end @@ -1148,6 +1144,12 @@ class Repository private + def refs_directory_exists? + return false unless path_with_namespace + + File.exist?(File.join(path_to_repo, 'refs')) + end + def cache @cache ||= RepositoryCache.new(path_with_namespace, @project.id) end |