Permalink
Browse files

almost fisted

  • Loading branch information...
1 parent 0cd4286 commit c94651f8c822f7c0778c03eb36bee5ca19f35911 @tenderlove tenderlove committed Feb 4, 2011
View
26 activerecord/lib/active_record/base.rb
@@ -679,16 +679,12 @@ def table_exists?
# Returns an array of column objects for the table associated with this class.
def columns
- @@columns[table_name] ||= connection.columns(
- table_name, "#{name} Columns"
- ).tap { |columns|
- columns.each { |column| column.primary = column.name == primary_key }
- }
+ connection_pool.columns[table_name]
end
# Returns a hash of column objects for the table associated with this class.
def columns_hash
- @@columns_hash[table_name] ||= Hash[columns.map { |column| [column.name, column] }]
+ connection_pool.columns_hash[table_name]
end
# Returns an array of column names as strings.
@@ -745,21 +741,14 @@ def column_methods_hash #:nodoc:
def reset_column_information
connection.clear_cache!
undefine_attribute_methods
- reset_column_cache
+ connection_pool.clear_table_cache!(table_name) if table_exists?
+
@column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
@arel_engine = @relation = nil
end
def clear_cache! # :nodoc:
- @@columns.clear
- @@columns_hash.clear
- @@arel_tables.clear
- end
-
- def reset_column_cache # :nodoc:
- @@columns.delete table_name
- @@columns_hash.delete table_name
- @@arel_tables.delete table_name
+ connection_pool.clear_cache!
end
def attribute_method?(attribute)
@@ -858,7 +847,7 @@ def sti_name
end
def arel_table
- @@arel_tables[table_name] ||= Arel::Table.new(table_name, arel_engine)
+ Arel::Table.new(table_name, arel_engine)
end
def arel_engine
@@ -1406,9 +1395,6 @@ def encode_quoted_value(value) #:nodoc:
quoted_value
end
end
- @@columns_hash = {}
- @@columns = {}
- @@arel_tables = {}
public
# New objects can be instantiated as either empty (pass no construction parameter) or pre-set with
View
7 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -125,6 +125,13 @@ def clear_cache!
@primary_keys.clear
end
+ # Clear out internal caches for table with +table_name+
+ def clear_table_cache!(table_name)
+ @columns.delete table_name
+ @columns_hash.delete table_name
+ @primary_keys.delete table_name
+ end
+
# Retrieve the connection associated with the current thread, or call
# #checkout to obtain one if necessary.
#
View
4 activerecord/lib/active_record/session_store.rb
@@ -59,12 +59,12 @@ def unmarshal(data)
end
def drop_table!
- reset_column_cache
+ connection_pool.clear_table_cache!(table_name)
connection.drop_table table_name
end
def create_table!
- reset_column_cache
+ connection_pool.clear_table_cache!(table_name)
connection.create_table(table_name) do |t|
t.string session_id_column, :limit => 255
t.text data_column_name
View
4 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -757,10 +757,10 @@ def test_caching_of_columns
david = Developer.find(1)
# clear cache possibly created by other tests
david.projects.reset_column_information
- assert_queries(0) { david.projects.columns; david.projects.columns }
+ assert_queries(1) { david.projects.columns; david.projects.columns }
# and again to verify that reset_column_information clears the cache correctly
david.projects.reset_column_information
- assert_queries(0) { david.projects.columns; david.projects.columns }
+ assert_queries(1) { david.projects.columns; david.projects.columns }
end
def test_attributes_are_being_set_when_initialized_from_habm_association_with_where_clause

0 comments on commit c94651f

Please sign in to comment.