mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'remove-thread-local-var'
This commit is contained in:
commit
b9cc147241
1 changed files with 12 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "set"
|
||||
require "active_record/connection_adapters/determine_if_preparable_visitor"
|
||||
require "active_record/connection_adapters/schema_cache"
|
||||
require "active_record/connection_adapters/sql_type_metadata"
|
||||
|
@ -10,7 +11,6 @@ require "arel/collectors/bind"
|
|||
require "arel/collectors/composite"
|
||||
require "arel/collectors/sql_string"
|
||||
require "arel/collectors/substitute_binds"
|
||||
require "concurrent/atomic/thread_local_var"
|
||||
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters # :nodoc:
|
||||
|
@ -92,10 +92,10 @@ module ActiveRecord
|
|||
@lock = ActiveSupport::Concurrency::LoadInterlockAwareMonitor.new
|
||||
|
||||
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
|
||||
@prepared_statement_status = Concurrent::ThreadLocalVar.new(true)
|
||||
@prepared_statements = true
|
||||
@visitor.extend(DetermineIfPreparableVisitor)
|
||||
else
|
||||
@prepared_statement_status = Concurrent::ThreadLocalVar.new(false)
|
||||
@prepared_statements = false
|
||||
end
|
||||
|
||||
@advisory_locks_enabled = self.class.type_cast_config_to_boolean(
|
||||
|
@ -139,7 +139,11 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def prepared_statements
|
||||
@prepared_statement_status.value
|
||||
@prepared_statements && !prepared_statements_disabled_cache.include?(object_id)
|
||||
end
|
||||
|
||||
def prepared_statements_disabled_cache # :nodoc:
|
||||
Thread.current[:ar_prepared_statements_disabled_cache] ||= Set.new
|
||||
end
|
||||
|
||||
class Version
|
||||
|
@ -226,7 +230,10 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def unprepared_statement
|
||||
@prepared_statement_status.bind(false) { yield }
|
||||
cache = prepared_statements_disabled_cache.add(object_id) if @prepared_statements
|
||||
yield
|
||||
ensure
|
||||
cache&.delete(object_id)
|
||||
end
|
||||
|
||||
# Returns the human-readable name of the adapter. Use mixed case - one
|
||||
|
|
Loading…
Reference in a new issue