aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
diff options
context:
space:
mode:
authorEugene Kenny <elkenny@gmail.com>2017-04-24 21:10:47 +0100
committerEugene Kenny <elkenny@gmail.com>2017-07-06 14:21:07 +0100
commit6658e3746b236f84e27e711fced6a83b187ad2b1 (patch)
tree7b6fb771bdb70425016a6a8f59883d0ea8a773ba /activerecord/lib/active_record/relation/calculations.rb
parentc8ce3459648ce0f86646b564ce1c0bb16a4b48eb (diff)
downloadrails-6658e3746b236f84e27e711fced6a83b187ad2b1.tar.gz
rails-6658e3746b236f84e27e711fced6a83b187ad2b1.tar.bz2
rails-6658e3746b236f84e27e711fced6a83b187ad2b1.zip
Skip query cache for in_batches and friends
The `find_each`, `find_in_batches` and `in_batches` APIs usually operate on large numbers of records, where it's preferable not to load them all into memory at once. If the query cache is enabled, it will hold onto the query results until the end of the execution context (request/job), which means the memory used is still proportional to the total number of records. These queries are typically not repeated, so the query cache isn't desirable here.
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 8a54f8f2c3..aaba6c71f2 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -184,7 +184,7 @@ module ActiveRecord
relation.select_values = column_names.map { |cn|
@klass.has_attribute?(cn) || @klass.attribute_alias?(cn) ? arel_attribute(cn) : cn
}
- result = klass.connection.select_all(relation.arel, nil, bound_attributes)
+ result = skip_query_cache_if_necessary { klass.connection.select_all(relation.arel, nil, bound_attributes) }
result.cast_values(klass.attribute_types)
end
end
@@ -260,7 +260,7 @@ module ActiveRecord
query_builder = relation.arel
end
- result = @klass.connection.select_all(query_builder, nil, bound_attributes)
+ result = skip_query_cache_if_necessary { @klass.connection.select_all(query_builder, nil, bound_attributes) }
row = result.first
value = row && row.values.first
type = result.column_types.fetch(column_alias) do
@@ -311,7 +311,7 @@ module ActiveRecord
relation.group_values = group_fields
relation.select_values = select_values
- calculated_data = @klass.connection.select_all(relation.arel, nil, relation.bound_attributes)
+ calculated_data = skip_query_cache_if_necessary { @klass.connection.select_all(relation.arel, nil, relation.bound_attributes) }
if association
key_ids = calculated_data.collect { |row| row[group_aliases.first] }