From 45588fef7eef095d33beaf192b0b6a8c9c8af348 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 18 Sep 2017 06:42:47 +0900 Subject: Return `through_scope` only if the scope is not empty scope Related 2b5f5cdd7c1d95716de6a206b6d09ccbb006dc17. If `through_scope` is empty scope, it is unnecessary to merge it. And also, comparing relations is a little expensive (will cause `build_arel`). It is enough to use `empty_scope?` to determine whether empty scope. --- .../lib/active_record/associations/preloader/through_association.rb | 6 ++---- 1 file changed, 2 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 7b37ec2f41..26bcdcbcc4 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -67,9 +67,7 @@ module ActiveRecord id_map end - def reset_association(owners, association_name, through_scope) - should_reset = through_scope != through_reflection.klass.unscoped - + def reset_association(owners, association_name, should_reset) # Don't cache the association - we would only be caching a subset if should_reset owners.each { |owner| @@ -112,7 +110,7 @@ module ActiveRecord end end - scope + scope unless scope.empty_scope? end end end -- cgit v1.2.3