1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Cache the descends_from_activerecord? call to speed up query generation. [skaes] Closes #9765

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7723 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Michael Koziarski 2007-10-03 05:31:36 +00:00
parent eb5033ad6b
commit b4ec9904c6

View file

@ -907,6 +907,11 @@ module ActiveRecord #:nodoc:
end end
end end
def finder_needs_type_condition? #:nodoc:
# This is like this because benchmarking justifies the strange :false stuff
:true == (@finder_needs_type_condition ||= descends_from_active_record? ? :false : :true)
end
# Returns a string like 'Post id:integer, title:string, body:text' # Returns a string like 'Post id:integer, title:string, body:text'
def inspect def inspect
if self == Base if self == Base
@ -1199,9 +1204,9 @@ module ActiveRecord #:nodoc:
segments = [] segments = []
segments << sanitize_sql(scope[:conditions]) if scope && !scope[:conditions].blank? segments << sanitize_sql(scope[:conditions]) if scope && !scope[:conditions].blank?
segments << sanitize_sql(conditions) unless conditions.blank? segments << sanitize_sql(conditions) unless conditions.blank?
segments << type_condition unless descends_from_active_record? segments << type_condition if finder_needs_type_condition?
segments.compact! segments.delete_if{|s| s.blank?}
sql << "WHERE (#{segments.join(") AND (")}) " unless segments.all?(&:blank?) sql << "WHERE (#{segments.join(") AND (")}) " unless segments.empty?
end end
def type_condition def type_condition