Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9094

Show
Ignore:
Timestamp:
03/26/08 15:26:59 (3 months ago)
Author:
rick
Message:

More efficient association preloading code that compacts a through_records array in a central location. Closes #11427 [danger]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r9093 r9094  
    11*SVN* 
     2 
     3* More efficient association preloading code that compacts a through_records array in a central location.  Closes #11427 [danger] 
    24 
    35* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria,  Sunny Ripert] 
  • trunk/activerecord/lib/active_record/association_preload.rb

    r9075 r9094  
    116116            source = reflection.source_reflection.name 
    117117            through_records.first.class.preload_associations(through_records, source) 
    118             through_records.compact.each do |through_record| 
     118            through_records.each do |through_record| 
    119119              add_preloaded_record_to_collection(id_to_record_map[through_record[through_primary_key].to_i], 
    120120                                                 reflection.name, through_record.send(source)) 
    121121            end 
    122           end           
    123         else           
     122          end 
     123        else 
    124124          records.each {|record| record.send("set_#{reflection.name}_target", nil)} 
    125125 
    126126 
    127127          set_association_single_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options), reflection.primary_key_name) 
    128         end                                        
     128        end 
    129129      end 
    130130 
     
    141141            source = reflection.source_reflection.name 
    142142            through_records.first.class.preload_associations(through_records, source) 
    143             through_records.compact.each do |through_record| 
     143            through_records.each do |through_record| 
    144144              add_preloaded_records_to_collection(id_to_record_map[through_record[through_primary_key].to_i], 
    145145                                                 reflection.name, through_record.send(source)) 
     
    160160          preload_options = {:conditions => ["#{interface} = ?", reflection.options[:source_type]]} 
    161161 
     162          records.compact! 
    162163          records.first.class.preload_associations(records, through_association, preload_options) 
    163164 
    164165          # Dont cache the association - we would only be caching a subset 
    165166          through_records = [] 
    166           records.compact.each do |record| 
     167          records.each do |record| 
    167168            proxy = record.send(through_association) 
    168169 
     
    174175            end 
    175176          end 
    176           through_records = through_records.flatten 
     177          through_records.flatten! 
    177178        else 
    178179          records.first.class.preload_associations(records, through_association) 
    179           through_records = records.compact.map {|record| record.send(through_association)}.flatten 
    180         end 
     180          through_records = records.map {|record| record.send(through_association)}.flatten 
     181        end 
     182        through_records.compact! 
     183        through_records 
    181184      end 
    182185