aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
diff options
context:
space:
mode:
authorAli Ibrahim <aibrahim2k2@gmail.com>2019-03-29 11:18:48 -0400
committerAli Ibrahim <aibrahim2k2@gmail.com>2019-04-03 11:10:14 -0400
commit1c6e508ade793b5f2676e9218ab2f4cc9474f9ce (patch)
treed890ba17fd2abdb8fee40b3e4dd04259a79613cc /activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
parentbeb0bc9907a31d0cbd2ca68c79c57a9e375761e8 (diff)
downloadrails-1c6e508ade793b5f2676e9218ab2f4cc9474f9ce.tar.gz
rails-1c6e508ade793b5f2676e9218ab2f4cc9474f9ce.tar.bz2
rails-1c6e508ade793b5f2676e9218ab2f4cc9474f9ce.zip
Cache database version in schema cache
* The database version will get cached in the schema cache file during the schema cache dump. When the database version check happens, the version will be pulled from the schema cache and thus avoid querying the database for the version. * If the schema cache file doesn't exist, we'll query the database for the version and cache it on the schema cache object. * To facilitate this change, all connection adapters now implement #get_database_version and #database_version. #database_version returns the value from the schema cache. * To take advantage of the cached database version, the database version check will now happen after the schema cache is set on the connection in the connection pool.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb27
1 files changed, 14 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 8ca2cfa9ed..f5da19f0f6 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -55,8 +55,8 @@ module ActiveRecord
super(connection, logger, config)
end
- def version #:nodoc:
- @version ||= Version.new(version_string)
+ def get_database_version #:nodoc:
+ Version.new(version_string)
end
def mariadb? # :nodoc:
@@ -68,11 +68,11 @@ module ActiveRecord
end
def supports_index_sort_order?
- !mariadb? && version >= "8.0.1"
+ !mariadb? && database_version >= "8.0.1"
end
def supports_expression_index?
- !mariadb? && version >= "8.0.13"
+ !mariadb? && database_version >= "8.0.13"
end
def supports_transaction_isolation?
@@ -96,16 +96,16 @@ module ActiveRecord
end
def supports_datetime_with_precision?
- mariadb? || version >= "5.6.4"
+ mariadb? || database_version >= "5.6.4"
end
def supports_virtual_columns?
- mariadb? || version >= "5.7.5"
+ mariadb? || database_version >= "5.7.5"
end
# See https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html for more details.
def supports_optimizer_hints?
- !mariadb? && version >= "5.7.7"
+ !mariadb? && database_version >= "5.7.7"
end
def supports_advisory_locks?
@@ -526,12 +526,13 @@ module ActiveRecord
sql
end
- private
- def check_version
- if version < "5.5.8"
- raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.5.8."
- end
+ def check_version # :nodoc:
+ if database_version < "5.5.8"
+ raise "Your version of MySQL (#{database_version}) is too old. Active Record supports MySQL >= 5.5.8."
end
+ end
+
+ private
def initialize_type_map(m = type_map)
super
@@ -702,7 +703,7 @@ module ActiveRecord
end
def supports_rename_index?
- mariadb? ? false : version >= "5.7.6"
+ mariadb? ? false : database_version >= "5.7.6"
end
def configure_connection