Class: SolidCache::Record
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SolidCache::Record
- Defined in:
- app/models/solid_cache/record.rb
Direct Known Subclasses
Constant Summary collapse
- NULL_INSTRUMENTER =
ActiveSupport::Notifications::Instrumenter.new(ActiveSupport::Notifications::Fanout.new)
Class Method Summary collapse
- .disable_instrumentation(&block) ⇒ Object
- .each_shard(&block) ⇒ Object
- .with_instrumenter(instrumenter, &block) ⇒ Object
- .with_shard(shard, &block) ⇒ Object
Class Method Details
.disable_instrumentation(&block) ⇒ Object
12 13 14 |
# File 'app/models/solid_cache/record.rb', line 12 def disable_instrumentation(&block) with_instrumenter(NULL_INSTRUMENTER, &block) end |
.each_shard(&block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/solid_cache/record.rb', line 37 def each_shard(&block) return to_enum(:each_shard) unless block_given? if SolidCache.configuration.sharded? SolidCache.configuration.shard_keys.each do |shard| Record.with_shard(shard, &block) end else yield end end |
.with_instrumenter(instrumenter, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/solid_cache/record.rb', line 16 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 |
.with_shard(shard, &block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/models/solid_cache/record.rb', line 29 def with_shard(shard, &block) if shard && SolidCache.configuration.sharded? connected_to(shard: shard, role: default_role, prevent_writes: false, &block) else block.call end end |