mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
015051ecaf
commit
082f59842d
@ -4,7 +4,9 @@
|
|||||||
#
|
#
|
||||||
# Without this patch each time we close a DB connection we spin a thread
|
# 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
|
class StaticThreadLocalVar
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
|
|
||||||
@ -14,6 +16,9 @@ class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
|
|||||||
|
|
||||||
def bind(value)
|
def bind(value)
|
||||||
raise "attempting to change immutable local var" if value != @value
|
raise "attempting to change immutable local var" if value != @value
|
||||||
|
if block_given?
|
||||||
|
yield
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,6 +44,7 @@ class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
|
|||||||
@prepared_statement_status = Concurrent::ThreadLocalVar.new(true)
|
@prepared_statement_status = Concurrent::ThreadLocalVar.new(true)
|
||||||
@visitor.extend(DetermineIfPreparableVisitor)
|
@visitor.extend(DetermineIfPreparableVisitor)
|
||||||
else
|
else
|
||||||
|
#@prepared_statement_status = Concurrent::ThreadLocalVar.new(false)
|
||||||
@prepared_statement_status = StaticThreadLocalVar.new(false)
|
@prepared_statement_status = StaticThreadLocalVar.new(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,5 +52,6 @@ class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
|
|||||||
config.fetch(:advisory_locks, true)
|
config.fetch(:advisory_locks, true)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user