summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/current_settings.rb2
-rw-r--r--lib/gitlab/database.rb9
-rw-r--r--lib/gitlab/git/lfs_pointer_file.rb9
-rw-r--r--lib/gitlab/git/repository.rb5
4 files changed, 21 insertions, 4 deletions
diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb
index b7c596a973d..e392a015b91 100644
--- a/lib/gitlab/current_settings.rb
+++ b/lib/gitlab/current_settings.rb
@@ -70,7 +70,7 @@ module Gitlab
active_db_connection = ActiveRecord::Base.connection.active? rescue false
active_db_connection &&
- ActiveRecord::Base.connection.table_exists?('application_settings')
+ Gitlab::Database.cached_table_exists?('application_settings')
rescue ActiveRecord::NoDatabaseError
false
end
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb
index e51794fef99..76501dd50e8 100644
--- a/lib/gitlab/database.rb
+++ b/lib/gitlab/database.rb
@@ -183,6 +183,15 @@ module Gitlab
ActiveRecord::Base.connection
end
+ def self.cached_column_exists?(table_name, column_name)
+ connection.schema_cache.columns_hash(table_name).has_key?(column_name.to_s)
+ end
+
+ def self.cached_table_exists?(table_name)
+ # Rails 5 uses data_source_exists? instead of table_exists?
+ connection.schema_cache.table_exists?(table_name)
+ end
+
private_class_method :connection
def self.database_version
diff --git a/lib/gitlab/git/lfs_pointer_file.rb b/lib/gitlab/git/lfs_pointer_file.rb
index da12ed7d125..2ae0a889590 100644
--- a/lib/gitlab/git/lfs_pointer_file.rb
+++ b/lib/gitlab/git/lfs_pointer_file.rb
@@ -1,13 +1,16 @@
module Gitlab
module Git
class LfsPointerFile
+ VERSION = "https://git-lfs.github.com/spec/v1".freeze
+ VERSION_LINE = "version #{VERSION}".freeze
+
def initialize(data)
@data = data
end
def pointer
@pointer ||= <<~FILE
- version https://git-lfs.github.com/spec/v1
+ #{VERSION_LINE}
oid sha256:#{sha256}
size #{size}
FILE
@@ -20,6 +23,10 @@ module Gitlab
def sha256
@sha256 ||= Digest::SHA256.hexdigest(@data)
end
+
+ def inspect
+ "#<#{self.class}:#{object_id} @size=#{size}, @sha256=#{sha256.inspect}>"
+ end
end
end
end
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index fbc93542619..9811c447a01 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1002,8 +1002,9 @@ module Gitlab
# This only checks the root .gitattributes file,
# it does not traverse subfolders to find additional .gitattributes files
#
- # This method is around 30 times slower than `attributes`,
- # which uses `$GIT_DIR/info/attributes`
+ # This method is around 30 times slower than `attributes`, which uses
+ # `$GIT_DIR/info/attributes`. Consider caching AttributesAtRefParser
+ # and reusing that for multiple calls instead of this method.
def attributes_at(ref, file_path)
parser = AttributesAtRefParser.new(self, ref)
parser.attributes(file_path)