diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-30 17:47:09 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-30 17:47:09 -0700 |
commit | fcb92882b12a4a79a5c2901062cef009ec5f2fdc (patch) | |
tree | 1b4403aae6cf2759b25689653243483b0589e941 | |
parent | b4e0e17363ecaa7fcbd2291a2d7bdcca29eec723 (diff) | |
download | rails-fcb92882b12a4a79a5c2901062cef009ec5f2fdc.tar.gz rails-fcb92882b12a4a79a5c2901062cef009ec5f2fdc.tar.bz2 rails-fcb92882b12a4a79a5c2901062cef009ec5f2fdc.zip |
reduce relation allocations
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 82bf426b22..6cc9d6c079 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -85,9 +85,11 @@ module ActiveRecord def initialize(records, associations, preload_scope = nil) @records = Array.wrap(records).compact.uniq @associations = Array.wrap(associations) - @preload_scope = preload_scope || Relation.new(nil, nil) + @preload_scope = preload_scope || NULL_RELATION end + NULL_RELATION = Struct.new(:values).new({}) + def run unless records.empty? associations.each { |association| preload(association) } |