Skip to content

Commit

Permalink
Replace with_instrumenter if not available
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
djmb committed Feb 4, 2025
1 parent 16acb85 commit adbcbe0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/models/solid_cache/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ class Record < ActiveRecord::Base

class << self
def disable_instrumentation(&block)
connection.with_instrumenter(NULL_INSTRUMENTER, &block)
with_instrumenter(NULL_INSTRUMENTER, &block)
end

def with_instrumenter(instrumenter, &block)
if connection.respond_to?(:with_instrumenter)
connection.with_instrumenter(instrumenter, &block)
else
begin
old_instrumenter, ActiveSupport::IsolatedExecutionState[:active_record_instrumenter] = ActiveSupport::IsolatedExecutionState[:active_record_instrumenter], instrumenter
block.call
ensure
ActiveSupport::IsolatedExecutionState[:active_record_instrumenter] = old_instrumenter
end
end
end

def with_shard(shard, &block)
Expand Down

0 comments on commit adbcbe0

Please sign in to comment.