Skip to content

Commit

Permalink
Revert "Performance: freeze cached rows instead of duping"
Browse files Browse the repository at this point in the history
This reverts commit cd8e653.
  • Loading branch information
jeremy committed Aug 22, 2008
1 parent a5eb297 commit 6e3d2a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def all(*args)
# 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").map { |record| instantiate(record) }
connection.select_all(sanitize_sql(sql), "#{name} Load").collect! { |record| instantiate(record) }
end

# Checks whether a record exists in the database that matches conditions given. These conditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,21 @@ def columns_with_query_cache(*args)

private
def cache_sql(sql)
if @query_cache.has_key?(sql)
log_info(sql, "CACHE", 0.0)
@query_cache[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 }
else
@query_cache[sql] = yield.freeze
result.duplicable? ? result.dup : result
end
rescue TypeError
result
end
end
end
Expand Down

0 comments on commit 6e3d2a7

Please sign in to comment.