Skip to content
This repository
Browse code

Cache the descends_from_activerecord? call to speed up query generati…

…on. [skaes] Closes #9765

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7723 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b4ec9904c6f34331bbe32a304acf4b43e43a4f18 1 parent eb5033a
Michael Koziarski authored October 03, 2007

Showing 1 changed file with 8 additions and 3 deletions. Show diff stats Hide diff stats

  1. 11  activerecord/lib/active_record/base.rb
11  activerecord/lib/active_record/base.rb
@@ -907,6 +907,11 @@ def descends_from_active_record?
907 907
         end
908 908
       end
909 909
 
  910
+      def finder_needs_type_condition? #:nodoc:
  911
+        # This is like this because benchmarking justifies the strange :false stuff
  912
+        :true == (@finder_needs_type_condition ||= descends_from_active_record? ? :false : :true)
  913
+      end
  914
+
910 915
       # Returns a string like 'Post id:integer, title:string, body:text'
911 916
       def inspect
912 917
         if self == Base
@@ -1199,9 +1204,9 @@ def add_conditions!(sql, conditions, scope = :auto)
1199 1204
           segments = []
1200 1205
           segments << sanitize_sql(scope[:conditions]) if scope && !scope[:conditions].blank?
1201 1206
           segments << sanitize_sql(conditions) unless conditions.blank?
1202  
-          segments << type_condition unless descends_from_active_record?
1203  
-          segments.compact!
1204  
-          sql << "WHERE (#{segments.join(") AND (")}) " unless segments.all?(&:blank?)
  1207
+          segments << type_condition if finder_needs_type_condition?
  1208
+          segments.delete_if{|s| s.blank?}
  1209
+          sql << "WHERE (#{segments.join(") AND (")}) " unless segments.empty?
1205 1210
         end
1206 1211
 
1207 1212
         def type_condition

0 notes on commit b4ec990

Please sign in to comment.
Something went wrong with that request. Please try again.