diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-18 07:45:34 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-18 08:08:24 +0900 |
commit | 4bb4824ae711b7b550e8e33b428110575adaefac (patch) | |
tree | d313aeac8d6564bc9b09dfec7e51f88f3caa0519 /activerecord/lib | |
parent | 5daf89f838abfd0c56d4a09bd352c987bc64ff9a (diff) | |
download | rails-4bb4824ae711b7b550e8e33b428110575adaefac.tar.gz rails-4bb4824ae711b7b550e8e33b428110575adaefac.tar.bz2 rails-4bb4824ae711b7b550e8e33b428110575adaefac.zip |
Early return if `records.empty?` in `Preloader#preload`
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 62caf02a2c..e1754d4a19 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -91,13 +91,13 @@ module ActiveRecord # { author: :avatar } # [ :books, { author: :avatar } ] def preload(records, associations, preload_scope = nil) - records = Array.wrap(records).compact.uniq - associations = Array.wrap(associations) + records = records.compact if records.empty? [] else - associations.flat_map { |association| + records.uniq! + Array.wrap(associations).flat_map { |association| preloaders_on association, records, preload_scope } end |