aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-18 06:42:47 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-18 06:42:47 +0900
commit45588fef7eef095d33beaf192b0b6a8c9c8af348 (patch)
tree14d2736f022c2f4f86137f116b4bf0f4ed6fdd56 /activerecord
parent7f8f66e93136ef7ff602b6cdb1f6a7acfaafa486 (diff)
downloadrails-45588fef7eef095d33beaf192b0b6a8c9c8af348.tar.gz
rails-45588fef7eef095d33beaf192b0b6a8c9c8af348.tar.bz2
rails-45588fef7eef095d33beaf192b0b6a8c9c8af348.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb6
1 files changed, 2 insertions, 4 deletions
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