aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-10-03 05:31:36 +0000
committerMichael Koziarski <michael@koziarski.com>2007-10-03 05:31:36 +0000
commitb4ec9904c6f34331bbe32a304acf4b43e43a4f18 (patch)
tree8b0b0337a9d4a133c8a9e8804268cd8b787cb0ea
parenteb5033ad6b4a12a32e1493fb5b9aeee9eb75f10e (diff)
downloadrails-b4ec9904c6f34331bbe32a304acf4b43e43a4f18.tar.gz
rails-b4ec9904c6f34331bbe32a304acf4b43e43a4f18.tar.bz2
rails-b4ec9904c6f34331bbe32a304acf4b43e43a4f18.zip
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
-rwxr-xr-xactiverecord/lib/active_record/base.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 34685a78e1..df15457a9a 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -907,6 +907,11 @@ module ActiveRecord #:nodoc:
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'
def inspect
if self == Base
@@ -1199,9 +1204,9 @@ module ActiveRecord #:nodoc:
segments = []
segments << sanitize_sql(scope[:conditions]) if scope && !scope[:conditions].blank?
segments << sanitize_sql(conditions) unless conditions.blank?
- segments << type_condition unless descends_from_active_record?
- segments.compact!
- sql << "WHERE (#{segments.join(") AND (")}) " unless segments.all?(&:blank?)
+ segments << type_condition if finder_needs_type_condition?
+ segments.delete_if{|s| s.blank?}
+ sql << "WHERE (#{segments.join(") AND (")}) " unless segments.empty?
end
def type_condition