diff options
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/action_view_output/context.rb | 41 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/file/template.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/content_disposition.rb | 54 | ||||
-rw-r--r-- | lib/gitlab/database.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/patch/active_record_query_cache.rb | 39 | ||||
-rw-r--r-- | lib/gitlab/query_limiting/middleware.rb | 4 |
7 files changed, 10 insertions, 143 deletions
diff --git a/lib/gitlab/action_view_output/context.rb b/lib/gitlab/action_view_output/context.rb deleted file mode 100644 index 9fbc9811636..00000000000 --- a/lib/gitlab/action_view_output/context.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -# This file was simplified from https://raw.githubusercontent.com/rails/rails/195f39804a7a4a0034f25e8704220e03d95a752a/actionview/lib/action_view/context.rb. -# -# It is only needed by modules that need to call ActionView helper -# methods (e.g. those in -# https://github.com/rails/rails/tree/c4d3e202e10ae627b3b9c34498afb45450652421/actionview/lib/action_view/helpers) -# to generate tags outside of a Rails controller (e.g. API, Sidekiq, -# etc.). -# -# In Rails 5, ActionView::Context automatically includes CompiledTemplates. -# This means that any module that includes ActionView::Context is now a descendant -# of CompiledTemplates. -# -# When a partial is rendered for the first time, it runs -# Module#module_eval, which will evaluate a string source that defines a -# new method. For example: -# -# def _app_views_profiles_show_html_haml___1285955918103175884_70307801785400(local_assigns, output_buffer) -# "hello world" -# end -# -# When a new method is defined, the Ruby interpreter clears the method -# cache for all descendants, and all methods for those modules will have -# to be redefined. This can lead to a significant performance penalty. -# -# Rails 6 fixes this behavior by moving out the `include -# CompiledTemplates` into ActionView::Base so that including `ActionView::Context` -# doesn't quietly affect other modules in this way. - -if Rails::VERSION::STRING.start_with?('6') - raise 'This module is no longer needed in Rails 6. Use ActionView::Context instead.' -end - -module Gitlab - module ActionViewOutput - module Context - attr_accessor :output_buffer, :view_flow - end - end -end diff --git a/lib/gitlab/ci/config/external/file/template.rb b/lib/gitlab/ci/config/external/file/template.rb index db56f6a9b00..c4b4a7a0a73 100644 --- a/lib/gitlab/ci/config/external/file/template.rb +++ b/lib/gitlab/ci/config/external/file/template.rb @@ -33,7 +33,7 @@ module Gitlab def template_name return unless template_name_valid? - location.first(-SUFFIX.length) + location.delete_suffix(SUFFIX) end def template_name_valid? diff --git a/lib/gitlab/content_disposition.rb b/lib/gitlab/content_disposition.rb deleted file mode 100644 index ff6154a5b26..00000000000 --- a/lib/gitlab/content_disposition.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true -# This ports ActionDispatch::Http::ContentDisposition (https://github.com/rails/rails/pull/33829, -# which will be available in Rails 6. -module Gitlab - class ContentDisposition # :nodoc: - # Make sure we remove this patch starting with Rails 6.0. - if Rails.version.start_with?('6.0') - raise <<~MSG - Please remove this file and use `ActionDispatch::Http::ContentDisposition` instead. - MSG - end - - def self.format(disposition:, filename:) - new(disposition: disposition, filename: filename).to_s - end - - attr_reader :disposition, :filename - - def initialize(disposition:, filename:) - @disposition = disposition - @filename = filename - end - - # rubocop:disable Style/VariableInterpolation - TRADITIONAL_ESCAPED_CHAR = /[^ A-Za-z0-9!#$+.^_`|~-]/.freeze - - def ascii_filename - 'filename="' + percent_escape(::I18n.transliterate(filename), TRADITIONAL_ESCAPED_CHAR) + '"' - end - - RFC_5987_ESCAPED_CHAR = /[^A-Za-z0-9!#$&+.^_`|~-]/.freeze - # rubocop:enable Style/VariableInterpolation - - def utf8_filename - "filename*=UTF-8''" + percent_escape(filename, RFC_5987_ESCAPED_CHAR) - end - - def to_s - if filename - "#{disposition}; #{ascii_filename}; #{utf8_filename}" - else - "#{disposition}" - end - end - - private - - def percent_escape(string, pattern) - string.gsub(pattern) do |char| - char.bytes.map { |byte| "%%%02X" % byte }.join - end - end - end -end diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 82ec740ade1..a614e68703c 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -204,15 +204,16 @@ module Gitlab # pool_size - The size of the DB pool. # host - An optional host name to use instead of the default one. def self.create_connection_pool(pool_size, host = nil, port = nil) - # See activerecord-4.2.7.1/lib/active_record/connection_adapters/connection_specification.rb env = Rails.env - original_config = ActiveRecord::Base.configurations + original_config = ActiveRecord::Base.configurations.to_h env_config = original_config[env].merge('pool' => pool_size) env_config['host'] = host if host env_config['port'] = port if port - config = original_config.merge(env => env_config) + config = ActiveRecord::DatabaseConfigurations.new( + original_config.merge(env => env_config) + ) spec = ActiveRecord:: diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index b53e01e6ff2..3b6684b861c 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -382,7 +382,7 @@ module Gitlab count_arel = table.project(Arel.star.count.as('count')) count_arel = yield table, count_arel if block_given? - total = exec_query(count_arel.to_sql).to_hash.first['count'].to_i + total = exec_query(count_arel.to_sql).to_a.first['count'].to_i return if total == 0 @@ -399,7 +399,7 @@ module Gitlab start_arel = table.project(table[:id]).order(table[:id].asc).take(1) start_arel = yield table, start_arel if block_given? - start_id = exec_query(start_arel.to_sql).to_hash.first['id'].to_i + start_id = exec_query(start_arel.to_sql).to_a.first['id'].to_i loop do stop_arel = table.project(table[:id]) @@ -409,7 +409,7 @@ module Gitlab .skip(batch_size) stop_arel = yield table, stop_arel if block_given? - stop_row = exec_query(stop_arel.to_sql).to_hash.first + stop_row = exec_query(stop_arel.to_sql).to_a.first update_arel = Arel::UpdateManager.new .table(table) diff --git a/lib/gitlab/patch/active_record_query_cache.rb b/lib/gitlab/patch/active_record_query_cache.rb deleted file mode 100644 index d6b649cdea7..00000000000 --- a/lib/gitlab/patch/active_record_query_cache.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -# Fixes a bug where the query cache isn't aware of the shared -# ActiveRecord connection used in tests -# https://github.com/rails/rails/issues/36587 - -# To be removed with https://gitlab.com/gitlab-org/gitlab-foss/issues/64413 - -module Gitlab - module Patch - module ActiveRecordQueryCache - # rubocop:disable Gitlab/ModuleWithInstanceVariables - def enable_query_cache! - @query_cache_enabled[connection_cache_key(current_thread)] = true - connection.enable_query_cache! if active_connection? - end - - def disable_query_cache! - @query_cache_enabled.delete connection_cache_key(current_thread) - connection.disable_query_cache! if active_connection? - end - - def query_cache_enabled - @query_cache_enabled[connection_cache_key(current_thread)] - end - - def active_connection? - @thread_cached_conns[connection_cache_key(current_thread)] - end - - private - - def current_thread - @lock_thread || Thread.current - end - # rubocop:enable Gitlab/ModuleWithInstanceVariables - end - end -end diff --git a/lib/gitlab/query_limiting/middleware.rb b/lib/gitlab/query_limiting/middleware.rb index f6ffbfe2645..714fe42884a 100644 --- a/lib/gitlab/query_limiting/middleware.rb +++ b/lib/gitlab/query_limiting/middleware.rb @@ -37,10 +37,10 @@ module Gitlab controller = env[CONTROLLER_KEY] action = "#{controller.class.name}##{controller.action_name}" - if controller.content_type == 'text/html' + if controller.media_type == 'text/html' action else - "#{action} (#{controller.content_type})" + "#{action} (#{controller.media_type})" end end |