aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-05-11 12:44:05 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-05-11 12:52:32 +0900
commit07a611e02351b32100f19495a34ed46d01f195c1 (patch)
treec07e9bdb83b0703df3cb026215f1a29d15d5903f /activerecord/lib/active_record
parent97bd56e674603529d96c6f6e85d695dd24208afb (diff)
downloadrails-07a611e02351b32100f19495a34ed46d01f195c1.tar.gz
rails-07a611e02351b32100f19495a34ed46d01f195c1.tar.bz2
rails-07a611e02351b32100f19495a34ed46d01f195c1.zip
Don't eager loading if unneeded for `FinderMethods#exists?`
Fixes #29025.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation.rb3
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb6
2 files changed, 5 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 5775eda5a5..333ad16e11 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -269,8 +269,7 @@ module ActiveRecord
# Returns true if there are no records.
def empty?
return @records.empty? if loaded?
-
- limit_value == 0 || !exists?
+ !exists?
end
# Returns true if there are no records.
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index a1459c87c6..1d661fa8ed 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -307,9 +307,11 @@ module ActiveRecord
MSG
end
- return false if !conditions
+ return false if !conditions || limit_value == 0
+
+ relation = self unless eager_loading?
+ relation ||= apply_join_dependency(self, construct_join_dependency(eager_loading: false))
- relation = apply_join_dependency(self, construct_join_dependency(eager_loading: false))
return false if ActiveRecord::NullRelation === relation
relation = construct_relation_for_exists(relation, conditions)