diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-21 14:26:42 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-26 13:44:11 -0700 |
commit | fca229e205e7d417a025198825cfe19c5c395bff (patch) | |
tree | d076f36fece816079a1ed8c9a02b50e21eae067b | |
parent | 02128d628c4084eccd93c41db40f4d83db17f53c (diff) | |
download | rails-fca229e205e7d417a025198825cfe19c5c395bff.tar.gz rails-fca229e205e7d417a025198825cfe19c5c395bff.tar.bz2 rails-fca229e205e7d417a025198825cfe19c5c395bff.zip |
caching column values
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 04dbcff95c..28413ce7a9 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -314,8 +314,8 @@ module ActiveRecord end def clear_cache! - @statements.values.each do |stmt| - stmt.close + @statements.values.each do |cache| + cache[:stmt].close end @statements.clear end @@ -324,17 +324,24 @@ module ActiveRecord log(sql, name) do result = nil + cache = {} if bind_values.empty? stmt = @connection.prepare(sql) else - stmt = @statements[sql] ||= @connection.prepare(sql) + cache = @statements[sql] ||= { + :stmt => @connection.prepare(sql) + } + stmt = cache[:stmt] end stmt.execute(*bind_values.map { |col, val| col ? col.type_cast(val) : val }) if metadata = stmt.result_metadata - cols = metadata.fetch_fields.map { |field| field.name } + cols = cache[:cols] ||= metadata.fetch_fields.map { |field| + field.name + } + metadata.free result = ActiveRecord::Result.new(cols, stmt.to_a) end |