From 1e4ca06c4898a61969a9f3375252d6a5c2087ac0 Mon Sep 17 00:00:00 2001 From: Dave Gynn Date: Sun, 26 Jul 2015 10:49:00 -0700 Subject: [PATCH] skip _select! call unless :select values are specified the default scope will select all fields. removing this improves performance and reduces String creation. --- .../lib/active_record/associations/preloader/association.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 1dc8bff193..026de7e525 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -137,7 +137,9 @@ module ActiveRecord scope.where_clause = reflection_scope.where_clause + preload_scope.where_clause scope.references_values = Array(values[:references]) + Array(preload_values[:references]) - scope._select! preload_values[:select] || values[:select] || table[Arel.star] + if preload_values[:select] || values[:select] + scope._select!(preload_values[:select] || values[:select]) + end scope.includes! preload_values[:includes] || values[:includes] if preload_scope.joins_values.any? scope.joins!(preload_scope.joins_values)