Skip to content

Commit e815c66

Browse files
committed
Make public method for schema_cache_ignored_tables?
Previously we only provided a method to set the ignored schema cache tables, but there was no way to ask if a table was ignored by the schema cache. Applications may want to implement their own schema cache, or at least run this check. Rather than forcing them to implement an internal method, this adds a way to ask whether a table is ignored by the schema cache code. Usage: ```ruby ActiveRecord.schema_cache_ignored_tables = ["developers"] ActiveRecord.schema_cache_ignored_tables?("developers") ```
1 parent 1b534a4 commit e815c66

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

activerecord/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
* Add public method for checking if a table is ignored by the schema cache.
2+
3+
Previously, an application would need to reimplement `ignored_table?` from the schema cache class to check if a table was set to be ignored. This adds a public method to support this and updates the schema cache to use that directly.
4+
5+
```ruby
6+
ActiveRecord.schema_cache_ignored_tables = ["developers"]
7+
ActiveRecord.schema_cache_ignored_tables?("developers")
8+
=> true
9+
```
10+
11+
*Eileen M. Uchitelle*
112

213
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activerecord/CHANGELOG.md) for previous changes.

activerecord/lib/active_record.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ module Tasks
196196
singleton_class.attr_accessor :schema_cache_ignored_tables
197197
self.schema_cache_ignored_tables = []
198198

199+
# Checks to see if the +table_name+ is ignored by checking
200+
# against the +schema_cache_ignored_tables` option.
201+
#
202+
# table_ignored?(:developers)
203+
#
204+
def self.schema_cache_ignored_table?(table_name)
205+
ActiveRecord.schema_cache_ignored_tables.any? do |ignored|
206+
ignored === table_name
207+
end
208+
end
209+
199210
singleton_class.attr_reader :default_timezone
200211

201212
# Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling

activerecord/lib/active_record/connection_adapters/schema_cache.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,7 @@ def tables_to_cache(pool)
434434
end
435435

436436
def ignored_table?(table_name)
437-
ActiveRecord.schema_cache_ignored_tables.any? do |ignored|
438-
ignored === table_name
439-
end
437+
ActiveRecord.schema_cache_ignored_table?(table_name)
440438
end
441439

442440
def derive_columns_hash_and_deduplicate_values

0 commit comments

Comments
 (0)