Skip to content

Commit c4b7ec5

Browse files
committed
review fixes
- restore arel_table reset - changelog was wrong - always instantiate find_by_statement_cache - the inherited_hook is no longer useful for instantiating because contexts may not have been created yet, but it is still useful for resetting statement caches for contexts that _have_ been created - column_for_attribute can stay on ModelSchema
1 parent e865dd2 commit c4b7ec5

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

activerecord/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Previously, models cached many adapter specific values which would prevent
55
making queries against different database types. Now, those caches are per
6-
`schema-context`, which can be configured in `database.yml`:
6+
`schema_context`, which can be configured in `database.yml`:
77

88
```yaml
99
primary:

activerecord/lib/active_record/model_schema.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ def _returning_columns_for_insert(connection) # :nodoc:
493493
# person.column_for_attribute(:nothing)
494494
# # => #<ActiveRecord::ConnectionAdapters::NullColumn:0xXXX @name=nil, @sql_type=nil, @cast_type=#<Type::Value>, ...>
495495
def column_for_attribute(name)
496-
model_schema.column_for_attribute(name)
496+
name = name.to_s
497+
columns_hash.fetch(name) do
498+
ConnectionAdapters::NullColumn.new(name)
499+
end
497500
end
498501

499502
# Returns a hash where the keys are column names and the values are
@@ -586,6 +589,7 @@ def initialize_load_schema_monitor
586589

587590
def reload_schema_from_cache(recursive = true)
588591
@any_schema_loaded = false
592+
@arel_table = nil
589593
@attribute_names = nil
590594

591595
# Reset all Schema instances

activerecord/lib/active_record/model_schema/schema.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(model_class, context_key)
2525
@attributes_builder = nil
2626
@column_defaults = nil
2727
@_returning_columns_for_insert = nil
28-
@find_by_statement_cache = nil
28+
initialize_find_by_cache
2929
@content_columns = nil
3030
@symbol_column_to_string_name_hash = nil
3131
end
@@ -118,14 +118,6 @@ def symbol_column_to_string(name_symbol)
118118
@symbol_column_to_string_name_hash[name_symbol]
119119
end
120120

121-
# Returns the column object for a named attribute
122-
def column_for_attribute(name)
123-
name = name.to_s
124-
columns_hash.fetch(name) do
125-
ConnectionAdapters::NullColumn.new(name)
126-
end
127-
end
128-
129121
# Reset all cached schema state
130122
def reload_schema_from_cache
131123
@_returning_columns_for_insert = nil
@@ -142,7 +134,6 @@ def reload_schema_from_cache
142134
end
143135

144136
def cached_find_by_statement(connection, key, &block)
145-
@find_by_statement_cache ||= { true => Concurrent::Map.new, false => Concurrent::Map.new }
146137
cache = @find_by_statement_cache[connection.prepared_statements]
147138
cache.compute_if_absent(key) { StatementCache.create(connection, &block) }
148139
end

0 commit comments

Comments
 (0)