Module: PredictiveLoad::ActiveRecordCollectionObservation::Rails4RelationObservation

Defined in:
lib/predictive_load/active_record_collection_observation.rb

Instance Method Summary collapse

Instance Method Details

#to_aObject

this essentially intercepts the enumerable methods that would result in n+1s since most of those are delegated to :to_a in Rails 5+ in the ActiveRecord::Relation::Delegation module



31
32
33
34
35
36
37
# File 'lib/predictive_load/active_record_collection_observation.rb', line 31

def to_a
  record_array = super
  if record_array.size > 1 && collection_observer
    collection_observer.observe(record_array.dup)
  end
  record_array
end