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

Changeset 8531

Show
Ignore:
Timestamp:
01/02/08 21:39:49 (4 months ago)
Author:
rick
Message:

Optimize ActiveRecord::Base#exists? to use #select_all instead of #find. Closes #10605 [jamesh, fcheung, protocool]

Files:

Legend:

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

    r8524 r8531  
    11*SVN* 
     2 
     3* Optimize ActiveRecord::Base#exists? to use #select_all instead of #find.  Closes #10605 [jamesh, fcheung, protocool] 
    24 
    35* Don't unnecessarily load has_many associations in after_update callbacks.  Closes #6822 [stopdropandrew, canadaduane] 
  • trunk/activerecord/lib/active_record/base.rb

    r8496 r8531  
    549549      #   Person.exists?(['name LIKE ?', "%#{query}%"]) 
    550550      def exists?(id_or_conditions) 
    551         !find(:first, :select => "#{quoted_table_name}.#{primary_key}", 
    552               :conditions => expand_id_conditions(id_or_conditions)).nil? 
     551        connection.select_all( 
     552          construct_finder_sql( 
     553            :select     => "#{quoted_table_name}.#{primary_key}",  
     554            :conditions => expand_id_conditions(id_or_conditions),  
     555            :limit      => 1 
     556          ),  
     557          "#{name} Exists" 
     558        ).size > 0 
    553559      end 
    554560