From 89f0957a6c5c1f9de934bda73b5fe6d294e3bb6e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 27 Aug 2013 15:20:54 -0700 Subject: cache association reset calculation --- .../active_record/associations/preloader/through_association.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index b2e8f32625..d35ffafe97 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -27,15 +27,15 @@ module ActiveRecord def through_records_by_owner Preloader.new(owners, through_reflection.name, through_scope).run + should_reset = (through_scope != through_reflection.klass.unscoped) || + (reflection.options[:source_type] && through_reflection.collection?) + owners.each_with_object({}) do |owner, h| association = owner.association through_reflection.name through_records = Array(association.reader) # Dont cache the association - we would only be caching a subset - if (through_scope != through_reflection.klass.unscoped) || - (reflection.options[:source_type] && through_reflection.collection?) - association.reset - end + association.reset if should_reset h[owner] = through_records end -- cgit v1.2.3