DEV: bind for thread local vars should yield block

followup on #015051ec without this improvement monkey patch does not work.

bind should yield the block it is passed for it to work.
This commit is contained in:
Sam Saffron 2019-09-12 17:57:57 +10:00
parent 015051ecaf
commit 082f59842d

View File

@ -4,7 +4,9 @@
#
# Without this patch each time we close a DB connection we spin a thread
class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
module ::ActiveRecord
module ConnectionAdapters
class AbstractAdapter
class StaticThreadLocalVar
attr_reader :value
@ -14,6 +16,9 @@ class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
def bind(value)
raise "attempting to change immutable local var" if value != @value
if block_given?
yield
end
end
end
@ -39,6 +44,7 @@ class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
@prepared_statement_status = Concurrent::ThreadLocalVar.new(true)
@visitor.extend(DetermineIfPreparableVisitor)
else
#@prepared_statement_status = Concurrent::ThreadLocalVar.new(false)
@prepared_statement_status = StaticThreadLocalVar.new(false)
end
@ -46,5 +52,6 @@ class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
config.fetch(:advisory_locks, true)
)
end
end
end
end