Merge branch 'master' of github.com:rails/rails
This commit is contained in:
commit
3ee51c91c5
|
@ -120,6 +120,7 @@ module ActiveRecord
|
||||||
@quoted_column_names, @quoted_table_names = {}, {}
|
@quoted_column_names, @quoted_table_names = {}, {}
|
||||||
@prevent_writes = false
|
@prevent_writes = false
|
||||||
@visitor = arel_visitor
|
@visitor = arel_visitor
|
||||||
|
@statements = build_statement_pool
|
||||||
@lock = ActiveSupport::Concurrency::LoadInterlockAwareMonitor.new
|
@lock = ActiveSupport::Concurrency::LoadInterlockAwareMonitor.new
|
||||||
|
|
||||||
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
|
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
|
||||||
|
@ -492,11 +493,9 @@ module ActiveRecord
|
||||||
# this should be overridden by concrete adapters
|
# this should be overridden by concrete adapters
|
||||||
end
|
end
|
||||||
|
|
||||||
###
|
# Clear any caching the database adapter may be doing.
|
||||||
# Clear any caching the database adapter may be doing, for example
|
|
||||||
# clearing the prepared statement cache. This is database specific.
|
|
||||||
def clear_cache!
|
def clear_cache!
|
||||||
# this should be overridden by concrete adapters
|
@lock.synchronize { @statements.clear } if @statements
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if its required to reload the connection between requests for development mode.
|
# Returns true if its required to reload the connection between requests for development mode.
|
||||||
|
@ -718,6 +717,9 @@ module ActiveRecord
|
||||||
def arel_visitor
|
def arel_visitor
|
||||||
Arel::Visitors::ToSql.new(self)
|
Arel::Visitors::ToSql.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_statement_pool
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,8 +53,6 @@ module ActiveRecord
|
||||||
|
|
||||||
def initialize(connection, logger, connection_options, config)
|
def initialize(connection, logger, connection_options, config)
|
||||||
super(connection, logger, config)
|
super(connection, logger, config)
|
||||||
|
|
||||||
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def version #:nodoc:
|
def version #:nodoc:
|
||||||
|
@ -162,10 +160,9 @@ module ActiveRecord
|
||||||
|
|
||||||
# CONNECTION MANAGEMENT ====================================
|
# CONNECTION MANAGEMENT ====================================
|
||||||
|
|
||||||
# Clears the prepared statements cache.
|
def clear_cache! # :nodoc:
|
||||||
def clear_cache!
|
|
||||||
reload_type_map
|
reload_type_map
|
||||||
@statements.clear
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
#--
|
#--
|
||||||
|
@ -806,6 +803,10 @@ module ActiveRecord
|
||||||
Arel::Visitors::MySQL.new(self)
|
Arel::Visitors::MySQL.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_statement_pool
|
||||||
|
StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit]))
|
||||||
|
end
|
||||||
|
|
||||||
def mismatched_foreign_key(message, sql:, binds:)
|
def mismatched_foreign_key(message, sql:, binds:)
|
||||||
match = %r/
|
match = %r/
|
||||||
(?:CREATE|ALTER)\s+TABLE\s*(?:`?\w+`?\.)?`?(?<table>\w+)`?.+?
|
(?:CREATE|ALTER)\s+TABLE\s*(?:`?\w+`?\.)?`?(?<table>\w+)`?.+?
|
||||||
|
|
|
@ -253,9 +253,6 @@ module ActiveRecord
|
||||||
|
|
||||||
configure_connection
|
configure_connection
|
||||||
add_pg_encoders
|
add_pg_encoders
|
||||||
@statements = StatementPool.new @connection,
|
|
||||||
self.class.type_cast_config_to_integer(config[:statement_limit])
|
|
||||||
|
|
||||||
add_pg_decoders
|
add_pg_decoders
|
||||||
|
|
||||||
@type_map = Type::HashLookupTypeMap.new
|
@type_map = Type::HashLookupTypeMap.new
|
||||||
|
@ -264,13 +261,6 @@ module ActiveRecord
|
||||||
@use_insert_returning = @config.key?(:insert_returning) ? self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true
|
@use_insert_returning = @config.key?(:insert_returning) ? self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clears the prepared statements cache.
|
|
||||||
def clear_cache!
|
|
||||||
@lock.synchronize do
|
|
||||||
@statements.clear
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def truncate(table_name, name = nil)
|
def truncate(table_name, name = nil)
|
||||||
exec_query "TRUNCATE TABLE #{quote_table_name(table_name)}", name, []
|
exec_query "TRUNCATE TABLE #{quote_table_name(table_name)}", name, []
|
||||||
end
|
end
|
||||||
|
@ -828,6 +818,10 @@ module ActiveRecord
|
||||||
Arel::Visitors::PostgreSQL.new(self)
|
Arel::Visitors::PostgreSQL.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_statement_pool
|
||||||
|
StatementPool.new(@connection, self.class.type_cast_config_to_integer(@config[:statement_limit]))
|
||||||
|
end
|
||||||
|
|
||||||
def can_perform_case_insensitive_comparison_for?(column)
|
def can_perform_case_insensitive_comparison_for?(column)
|
||||||
@case_insensitive_cache ||= {}
|
@case_insensitive_cache ||= {}
|
||||||
@case_insensitive_cache[column.sql_type] ||= begin
|
@case_insensitive_cache[column.sql_type] ||= begin
|
||||||
|
|
|
@ -96,8 +96,7 @@ module ActiveRecord
|
||||||
def initialize(connection, logger, connection_options, config)
|
def initialize(connection, logger, connection_options, config)
|
||||||
super(connection, logger, config)
|
super(connection, logger, config)
|
||||||
|
|
||||||
@active = true
|
@active = true
|
||||||
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
|
|
||||||
configure_connection
|
configure_connection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -156,11 +155,6 @@ module ActiveRecord
|
||||||
@connection.close rescue nil
|
@connection.close rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clears the prepared statements cache.
|
|
||||||
def clear_cache!
|
|
||||||
@statements.clear
|
|
||||||
end
|
|
||||||
|
|
||||||
def truncate(table_name, name = nil)
|
def truncate(table_name, name = nil)
|
||||||
execute "DELETE FROM #{quote_table_name(table_name)}", name
|
execute "DELETE FROM #{quote_table_name(table_name)}", name
|
||||||
end
|
end
|
||||||
|
@ -613,6 +607,10 @@ module ActiveRecord
|
||||||
Arel::Visitors::SQLite.new(self)
|
Arel::Visitors::SQLite.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_statement_pool
|
||||||
|
StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit]))
|
||||||
|
end
|
||||||
|
|
||||||
def configure_connection
|
def configure_connection
|
||||||
execute("PRAGMA foreign_keys = ON", "SCHEMA")
|
execute("PRAGMA foreign_keys = ON", "SCHEMA")
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,6 +41,10 @@ if ActiveRecord::Base.connection.prepared_statements
|
||||||
topics = Topic.where(id: 1)
|
topics = Topic.where(id: 1)
|
||||||
assert_equal [1], topics.map(&:id)
|
assert_equal [1], topics.map(&:id)
|
||||||
assert_includes statement_cache, to_sql_key(topics.arel)
|
assert_includes statement_cache, to_sql_key(topics.arel)
|
||||||
|
|
||||||
|
@connection.clear_cache!
|
||||||
|
|
||||||
|
assert_not_includes statement_cache, to_sql_key(topics.arel)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_statement_cache_with_query_cache
|
def test_statement_cache_with_query_cache
|
||||||
|
|
Loading…
Reference in New Issue