Sha256: 81c57fc79ba9cb0951e3429aea0afc1af664a6dcd0288ea5bfe8d5a5606d2132
Contents?: true
Size: 1.04 KB
Versions: 17
Compression:
Stored size: 1.04 KB
Contents
module JitPreloader module ActiveRecordRelation def jit_preload(*args) spawn.jit_preload!(*args) end def jit_preload!(*args) @jit_preload = true self end def jit_preload? @jit_preload end def calculate(*args) if respond_to?(:proxy_association) && proxy_association.owner && proxy_association.owner.jit_n_plus_one_tracking ActiveSupport::Notifications.publish("n_plus_one_query", source: proxy_association.owner, association: "#{proxy_association.reflection.name}.#{args.first}") end super(*args) end def exec_queries super.tap do |records| if limit_value != 1 records.each{ |record| record.jit_n_plus_one_tracking = true } if jit_preload? || JitPreloader.globally_enabled? JitPreloader::Preloader.attach(records) end end end end end end ActiveRecord::Relation.prepend(JitPreloader::ActiveRecordRelation)
Version data entries
17 entries across 17 versions & 1 rubygems