Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJasper Maes <jaspermaes.jm@gmail.com>2018-12-15 12:06:56 +0300
committerJasper Maes <jaspermaes.jm@gmail.com>2018-12-16 12:48:41 +0300
commit56296f1edadf2bc5f7741cbb3f97cb41f090aac6 (patch)
tree5a21667acd7d431f155d12227181dcfc6d21cba8 /lib
parent8b4602041cf2c4a8738a4796d78720017249249f (diff)
Remove rails4 specific code
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers.rb2
-rw-r--r--lib/declarative_policy.rb12
-rw-r--r--lib/gitlab/database.rb6
-rw-r--r--lib/gitlab/database/arel_methods.rb20
-rw-r--r--lib/gitlab/database/median.rb17
-rw-r--r--lib/gitlab/database/migration_helpers.rb4
-rw-r--r--lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb4
-rw-r--r--lib/gitlab/database/sha_attribute.rb37
-rw-r--r--lib/gitlab/database/subquery.rb14
-rw-r--r--lib/gitlab/gpg.rb8
-rw-r--r--lib/gitlab/middleware/correlation_id.rb6
-rw-r--r--lib/mysql_zero_date.rb2
12 files changed, 23 insertions, 109 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 2cceb2ec798..a7d67a6300e 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -291,7 +291,7 @@ module API
end
end
permitted_attrs = ActionController::Parameters.new(attrs).permit!
- Gitlab.rails5? ? permitted_attrs.to_h : permitted_attrs
+ permitted_attrs.to_h
end
# rubocop: disable CodeReuse/ActiveRecord
diff --git a/lib/declarative_policy.rb b/lib/declarative_policy.rb
index 5e22523e45a..7ba48ae9c79 100644
--- a/lib/declarative_policy.rb
+++ b/lib/declarative_policy.rb
@@ -22,14 +22,10 @@ module DeclarativePolicy
key = Cache.policy_key(user, subject)
cache[key] ||=
- if Gitlab.rails5?
- # to avoid deadlocks in multi-threaded environment when
- # autoloading is enabled, we allow concurrent loads,
- # https://gitlab.com/gitlab-org/gitlab-ce/issues/48263
- ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
- class_for(subject).new(user, subject, opts)
- end
- else
+ # to avoid deadlocks in multi-threaded environment when
+ # autoloading is enabled, we allow concurrent loads,
+ # https://gitlab.com/gitlab-org/gitlab-ce/issues/48263
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
class_for(subject).new(user, subject, opts)
end
end
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb
index 6d40e00c035..b6ca777e029 100644
--- a/lib/gitlab/database.rb
+++ b/lib/gitlab/database.rb
@@ -232,11 +232,7 @@ module Gitlab
end
def self.cached_table_exists?(table_name)
- if Gitlab.rails5?
- connection.schema_cache.data_source_exists?(table_name)
- else
- connection.schema_cache.table_exists?(table_name)
- end
+ connection.schema_cache.data_source_exists?(table_name)
end
private_class_method :connection
diff --git a/lib/gitlab/database/arel_methods.rb b/lib/gitlab/database/arel_methods.rb
deleted file mode 100644
index 991e4152dcb..00000000000
--- a/lib/gitlab/database/arel_methods.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module Database
- module ArelMethods
- private
-
- # In Arel 7.0.0 (Arel 7.1.4 is used in Rails 5.0) the `engine` parameter of `Arel::UpdateManager#initializer`
- # was removed.
- # Remove this file and inline this method when removing rails5? code.
- def arel_update_manager
- if Gitlab.rails5?
- Arel::UpdateManager.new
- else
- Arel::UpdateManager.new(ActiveRecord::Base)
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/database/median.rb b/lib/gitlab/database/median.rb
index 0da5119a3ed..1455e410d4b 100644
--- a/lib/gitlab/database/median.rb
+++ b/lib/gitlab/database/median.rb
@@ -35,13 +35,7 @@ module Gitlab
end
def mysql_median_datetime_sql(arel_table, query_so_far, column_sym)
- arel_from = if Gitlab.rails5?
- arel_table.from
- else
- arel_table
- end
-
- query = arel_from
+ query = arel_table.from
.from(arel_table.project(Arel.sql('*')).order(arel_table[column_sym]).as(arel_table.table_name))
.project(average([arel_table[column_sym]], 'median'))
.where(
@@ -151,13 +145,8 @@ module Gitlab
.order(arel_table[column_sym])
).as('row_id')
- arel_from = if Gitlab.rails5?
- arel_table.from.from(arel_table.alias)
- else
- arel_table.from(arel_table.alias)
- end
-
- count = arel_from.project('COUNT(*)')
+ count = arel_table.from.from(arel_table.alias)
+ .project('COUNT(*)')
.where(arel_table[partition_column].eq(arel_table.alias[partition_column]))
.as('ct')
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index d9578852db6..3abd0600e9d 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -3,8 +3,6 @@
module Gitlab
module Database
module MigrationHelpers
- include Gitlab::Database::ArelMethods
-
BACKGROUND_MIGRATION_BATCH_SIZE = 1000 # Number of rows to process per job
BACKGROUND_MIGRATION_JOB_BUFFER_SIZE = 1000 # Number of jobs to bulk queue at a time
@@ -361,7 +359,7 @@ module Gitlab
stop_arel = yield table, stop_arel if block_given?
stop_row = exec_query(stop_arel.to_sql).to_hash.first
- update_arel = arel_update_manager
+ update_arel = Arel::UpdateManager.new
.table(table)
.set([[table[column], value]])
.where(table[:id].gteq(start_id))
diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
index a5b42bbfdd9..60afa4bcd52 100644
--- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
+++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
@@ -5,8 +5,6 @@ module Gitlab
module RenameReservedPathsMigration
module V1
class RenameBase
- include Gitlab::Database::ArelMethods
-
attr_reader :paths, :migration
delegate :update_column_in_batches,
@@ -66,7 +64,7 @@ module Gitlab
old_full_path,
new_full_path)
- update = arel_update_manager
+ update = Arel::UpdateManager.new
.table(routes)
.set([[routes[:path], replace_statement]])
.where(Arel::Nodes::SqlLiteral.new(filter))
diff --git a/lib/gitlab/database/sha_attribute.rb b/lib/gitlab/database/sha_attribute.rb
index 6516d6e648d..8d97adaff99 100644
--- a/lib/gitlab/database/sha_attribute.rb
+++ b/lib/gitlab/database/sha_attribute.rb
@@ -8,14 +8,7 @@ module Gitlab
# behaviour from the default Binary type.
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bytea
else
- # In Rails 5.0 `Type` has been moved from `ActiveRecord` to `ActiveModel`
- # https://github.com/rails/rails/commit/9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6#diff-f8ba7983a51d687976e115adcd95822b
- # Remove this method and leave just `ActiveModel::Type::Binary` when removing Gitlab.rails5? code.
- if Gitlab.rails5?
- ActiveModel::Type::Binary
- else
- ActiveRecord::Type::Binary
- end
+ ActiveModel::Type::Binary
end
# Class for casting binary data to hexadecimal SHA1 hashes (and vice-versa).
@@ -26,31 +19,9 @@ module Gitlab
class ShaAttribute < BINARY_TYPE
PACK_FORMAT = 'H*'.freeze
- # It is called from activerecord-4.2.10/lib/active_record internal methods.
- # Remove this method when removing Gitlab.rails5? code.
- def type_cast_from_database(value)
- unpack_sha(super)
- end
-
- # It is called from activerecord-4.2.10/lib/active_record internal methods.
- # Remove this method when removing Gitlab.rails5? code.
- def type_cast_for_database(value)
- serialize(value)
- end
-
- # It is called from activerecord-5.0.6/lib/active_record/attribute.rb
- # Remove this method when removing Gitlab.rails5? code..
- def deserialize(value)
- value = Gitlab.rails5? ? super : method(:type_cast_from_database).super_method.call(value)
-
- unpack_sha(value)
- end
-
- # Rename this method to `deserialize(value)` removing Gitlab.rails5? code.
# Casts binary data to a SHA1 in hexadecimal.
- def unpack_sha(value)
- # Uncomment this line when removing Gitlab.rails5? code.
- # value = super
+ def deserialize(value)
+ value = super(value)
value ? value.unpack(PACK_FORMAT)[0] : nil
end
@@ -58,7 +29,7 @@ module Gitlab
def serialize(value)
arg = value ? [value].pack(PACK_FORMAT) : nil
- Gitlab.rails5? ? super(arg) : method(:type_cast_for_database).super_method.call(arg)
+ super(arg)
end
end
end
diff --git a/lib/gitlab/database/subquery.rb b/lib/gitlab/database/subquery.rb
index 36e4559b554..10971d2b274 100644
--- a/lib/gitlab/database/subquery.rb
+++ b/lib/gitlab/database/subquery.rb
@@ -6,15 +6,11 @@ module Gitlab
class << self
def self_join(relation)
t = relation.arel_table
- t2 = if !Gitlab.rails5?
- relation.arel.as('t2')
- else
- # Work around a bug in Rails 5, where LIMIT causes trouble
- # See https://gitlab.com/gitlab-org/gitlab-ce/issues/51729
- r = relation.limit(nil).arel
- r.take(relation.limit_value) if relation.limit_value
- r.as('t2')
- end
+ # Work around a bug in Rails 5, where LIMIT causes trouble
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/51729
+ r = relation.limit(nil).arel
+ r.take(relation.limit_value) if relation.limit_value
+ t2 = r.as('t2')
relation.unscoped.joins(t.join(t2).on(t[:id].eq(t2[:id])).join_sources.first)
end
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb
index e53c2d00743..32f61b1d65c 100644
--- a/lib/gitlab/gpg.rb
+++ b/lib/gitlab/gpg.rb
@@ -73,13 +73,7 @@ module Gitlab
if MUTEX.locked? && MUTEX.owned?
optimistic_using_tmp_keychain(&block)
else
- if Gitlab.rails5?
- ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
- MUTEX.synchronize do
- optimistic_using_tmp_keychain(&block)
- end
- end
- else
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
MUTEX.synchronize do
optimistic_using_tmp_keychain(&block)
end
diff --git a/lib/gitlab/middleware/correlation_id.rb b/lib/gitlab/middleware/correlation_id.rb
index 73542dd422e..80dddc41c12 100644
--- a/lib/gitlab/middleware/correlation_id.rb
+++ b/lib/gitlab/middleware/correlation_id.rb
@@ -20,11 +20,7 @@ module Gitlab
private
def correlation_id(env)
- if Gitlab.rails5?
- request(env).request_id
- else
- request(env).uuid
- end
+ request(env).request_id
end
def request(env)
diff --git a/lib/mysql_zero_date.rb b/lib/mysql_zero_date.rb
index 216560148fa..f36610abf8f 100644
--- a/lib/mysql_zero_date.rb
+++ b/lib/mysql_zero_date.rb
@@ -17,4 +17,4 @@ module MysqlZeroDate
end
end
-ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(MysqlZeroDate) if Gitlab.rails5?
+ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(MysqlZeroDate)