mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Performance: freeze cached rows instead of duping
This commit is contained in:
@@ -612,7 +612,7 @@ module ActiveRecord #:nodoc:
|
||||
# Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
|
||||
# > [#<Post:0x36bff9c @attributes={"first_name"=>"The Cheap Man Buys Twice"}>, ...]
|
||||
def find_by_sql(sql)
|
||||
connection.select_all(sanitize_sql(sql), "#{name} Load").collect! { |record| instantiate(record) }
|
||||
connection.select_all(sanitize_sql(sql), "#{name} Load").map { |record| instantiate(record) }
|
||||
end
|
||||
|
||||
# Checks whether a record exists in the database that matches conditions given. These conditions
|
||||
|
||||
@@ -72,21 +72,12 @@ module ActiveRecord
|
||||
|
||||
private
|
||||
def cache_sql(sql)
|
||||
result =
|
||||
if @query_cache.has_key?(sql)
|
||||
log_info(sql, "CACHE", 0.0)
|
||||
@query_cache[sql]
|
||||
else
|
||||
@query_cache[sql] = yield
|
||||
end
|
||||
|
||||
if Array === result
|
||||
result.collect { |row| row.dup }
|
||||
if @query_cache.has_key?(sql)
|
||||
log_info(sql, "CACHE", 0.0)
|
||||
@query_cache[sql]
|
||||
else
|
||||
result.duplicable? ? result.dup : result
|
||||
@query_cache[sql] = yield.freeze
|
||||
end
|
||||
rescue TypeError
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user