Class: PredictiveLoad::PreloadLog
- Inherits:
-
ActiveRecord::Associations::Preloader
- Object
- ActiveRecord::Associations::Preloader
- PredictiveLoad::PreloadLog
- Defined in:
- lib/predictive_load/preload_log.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/predictive_load/preload_log.rb', line 6 def logger @logger end |
Instance Method Details
#collection_arel(preloader) ⇒ Object
28 29 30 31 32 |
# File 'lib/predictive_load/preload_log.rb', line 28 def collection_arel(preloader) owners_map = preloader.owners_by_key owner_keys = owners_map.keys.compact preloader.association_key.in(owner_keys) end |
#log(message) ⇒ Object
34 35 36 |
# File 'lib/predictive_load/preload_log.rb', line 34 def log() ActiveRecord::Base.logger.info("predictive_load: #{}") end |
#preload(association) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/predictive_load/preload_log.rb', line 8 def preload(association) grouped_records(association).each do |reflection, klasses| klasses.each do |klass, records| preloader = preloader_for(reflection).new(klass, records, reflection, preload_scope) if preloader.respond_to?(:through_reflection) log("encountered :through association for #{association}. Requires loading records to generate query, so skipping for now.") next end preload_sql = preloader.scope.where(collection_arel(preloader)).to_sql log("would preload with: #{preload_sql.to_s}") klass.connection.explain(preload_sql).each_line do |line| log(line) end end end end |