diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-09 10:05:09 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-09 10:05:09 -0800 |
commit | 99774f8ed3c4f356d318b38ade568ae0d9456de7 (patch) | |
tree | 5b860e207b3d788dd75372f1a774b62398dd46f9 /lib | |
parent | af5dd388cc1d5f58ac2f010730a301e0c7d7e6e6 (diff) | |
download | rails-99774f8ed3c4f356d318b38ade568ae0d9456de7.tar.gz rails-99774f8ed3c4f356d318b38ade568ae0d9456de7.tar.bz2 rails-99774f8ed3c4f356d318b38ade568ae0d9456de7.zip |
caches should be connection specific
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 9f581ee470..308a5bf400 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -10,8 +10,14 @@ module Arel @last_column = nil @quoted_tables = {} @quoted_columns = {} - @column_cache = Hash.new { |h,k| h[k] = {} } - @table_exists = {} + @column_cache = Hash.new { |h,conn| + h[conn] = Hash.new { |conn_h,column| + conn_h[column] = {} + } + } + @table_exists = Hash.new { |h,conn| + h[conn] = {} + } end def accept object @@ -69,13 +75,17 @@ module Arel end def table_exists? name - return true if @table_exists.key? name + return true if table_exists.key? name @connection.tables.each do |table| - @table_exists[table] = true + table_exists[table] = true end - @table_exists.key? name + table_exists.key? name + end + + def table_exists + @table_exists[@connection] end def column_for attr @@ -86,13 +96,16 @@ module Arel # If we don't have this column cached, get a list of columns and # cache them for this table - unless @column_cache.key? table - #$stderr.puts "MISS: #{self.class.name} #{object_id} #{table.inspect} : #{name.inspect}" + unless column_cache.key? table columns = @connection.columns(table, "#{table}(#{name}) Columns") - @column_cache[table] = Hash[columns.map { |c| [c.name.to_sym, c] }] + column_cache[table] = Hash[columns.map { |c| [c.name.to_sym, c] }] end - @column_cache[table][name] + column_cache[table][name] + end + + def column_cache + @column_cache[@connection] end def visit_Arel_Nodes_Values o |