Skip to content

Commit adbcbe0

Browse files
committed
Replace with_instrumenter if not available
`with_connection` was removed in rails/rails@dc522a3 This keeps things working for now, but we should consider finding a better way to handle this, rather than reaching into AR's internals.
1 parent 16acb85 commit adbcbe0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

app/models/solid_cache/record.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@ class Record < ActiveRecord::Base
1010

1111
class << self
1212
def disable_instrumentation(&block)
13-
connection.with_instrumenter(NULL_INSTRUMENTER, &block)
13+
with_instrumenter(NULL_INSTRUMENTER, &block)
14+
end
15+
16+
def with_instrumenter(instrumenter, &block)
17+
if connection.respond_to?(:with_instrumenter)
18+
connection.with_instrumenter(instrumenter, &block)
19+
else
20+
begin
21+
old_instrumenter, ActiveSupport::IsolatedExecutionState[:active_record_instrumenter] = ActiveSupport::IsolatedExecutionState[:active_record_instrumenter], instrumenter
22+
block.call
23+
ensure
24+
ActiveSupport::IsolatedExecutionState[:active_record_instrumenter] = old_instrumenter
25+
end
26+
end
1427
end
1528

1629
def with_shard(shard, &block)

0 commit comments

Comments
 (0)