aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2017-05-11 13:41:10 -0700
committerGitHub <noreply@github.com>2017-05-11 13:41:10 -0700
commit358280d980685717fc49fb2f6cfb4a0507bfe23f (patch)
treed0ee4659c5552f2892ec40f2224468c28058c8af /activerecord/lib/active_record
parentf73b845610931ddf03c756d804982776a3cc69a4 (diff)
parent07a611e02351b32100f19495a34ed46d01f195c1 (diff)
downloadrails-358280d980685717fc49fb2f6cfb4a0507bfe23f.tar.gz
rails-358280d980685717fc49fb2f6cfb4a0507bfe23f.tar.bz2
rails-358280d980685717fc49fb2f6cfb4a0507bfe23f.zip
Merge pull request #29043 from kamipo/dont_eager_loading_if_unneeded_for_exists
Don't eager loading if unneeded for `FinderMethods#exists?`
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)