aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAli Ibrahim <aibrahim2k2@gmail.com>2019-04-10 14:13:21 -0400
committerAli Ibrahim <aibrahim2k2@gmail.com>2019-04-11 12:57:19 -0400
commit6584fb3939dd3892834ed93fa791064d5299cda2 (patch)
treeaa6b25c50f13e543c3eeb35d5f44209d212f6a62
parentb86f32bc8529caa767e166aa10725a0fe1add7b5 (diff)
downloadrails-6584fb3939dd3892834ed93fa791064d5299cda2.tar.gz
rails-6584fb3939dd3892834ed93fa791064d5299cda2.tar.bz2
rails-6584fb3939dd3892834ed93fa791064d5299cda2.zip
Cache full MySQL version in schema cache
* The database version is cached in all the adapters, but this didn't include the full MySQL version. Anything that uses the full MySQL version would need to query the database to get that data even if they're using the schema cache. * Now the full MySQL version will be cached in the schema cache via the Version object.
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb5
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb14
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb8
-rw-r--r--activerecord/test/cases/connection_adapters/schema_cache_test.rb4
4 files changed, 25 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 200184c2f9..bf0bb84c93 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -170,8 +170,11 @@ module ActiveRecord
class Version
include Comparable
- def initialize(version_string)
+ attr_reader :full_version_string
+
+ def initialize(version_string, full_version_string = nil)
@version = version_string.split(".").map(&:to_i)
+ @full_version_string = full_version_string
end
def <=>(version_string)
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 ca8bbc14da..75bc94c49c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -51,12 +51,20 @@ module ActiveRecord
end
end
+ class Version < AbstractAdapter::Version # :nodoc:
+ def initialize(version_string, full_version_string)
+ super
+ end
+ end
+
def initialize(connection, logger, connection_options, config)
super(connection, logger, config)
end
def get_database_version #:nodoc:
- Version.new(version_string)
+ full_version_string = get_full_version
+ version_string = version_string(full_version_string)
+ Version.new(version_string, full_version_string)
end
def mariadb? # :nodoc:
@@ -801,8 +809,8 @@ module ActiveRecord
MismatchedForeignKey.new(options)
end
- def version_string
- full_version.match(/^(?:5\.5\.5-)?(\d+\.\d+\.\d+)/)[1]
+ def version_string(full_version_string) # :nodoc:
+ full_version_string.match(/^(?:5\.5\.5-)?(\d+\.\d+\.\d+)/)[1]
end
class MysqlString < Type::String # :nodoc:
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 0dc880c731..2ff411a058 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -125,8 +125,12 @@ module ActiveRecord
super
end
- def full_version
- @full_version ||= @connection.server_info[:version]
+ def full_version # :nodoc:
+ schema_cache.database_version.full_version_string
+ end
+
+ def get_full_version # :nodoc:
+ @connection.server_info[:version]
end
end
end
diff --git a/activerecord/test/cases/connection_adapters/schema_cache_test.rb b/activerecord/test/cases/connection_adapters/schema_cache_test.rb
index 89a9c30f9b..28e232b88f 100644
--- a/activerecord/test/cases/connection_adapters/schema_cache_test.rb
+++ b/activerecord/test/cases/connection_adapters/schema_cache_test.rb
@@ -95,6 +95,10 @@ module ActiveRecord
assert_no_queries do
assert_equal @database_version.to_s, @cache.database_version.to_s
+
+ if current_adapter?(:Mysql2Adapter)
+ assert_not_nil @cache.database_version.full_version_string
+ end
end
end