From c900cdfdc3ee8c5d0a880698c128e620ac0c86fc Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 16 Jan 2020 07:00:51 +0900 Subject: [PATCH] Avoid extra Array allocation --- .../lib/active_record/associations/preloader/association.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index fb620b0f7b..e4e1b6be5e 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -48,18 +48,18 @@ module ActiveRecord raw_records = owner_keys.empty? ? [] : records_for(owner_keys) @preloaded_records = raw_records.select do |record| - assignments = [] + assignments = false owners_by_key[convert_key(record[association_key_name])].each do |owner| entries = (@records_by_owner[owner] ||= []) if reflection.collection? || entries.empty? entries << record - assignments << record + assignments = true end end - !assignments.empty? + assignments end end