Skip to content

Commit c0a87f8

Browse files
committed
drop unnecessary load_schema statements
Before rails 7.2: All of this data was set in `load_schema!` so we needed to ensure the schema was loaded to access _virtual_includes or _virtual_arel. Same may be the case for has_attribute? After rails 7.2: It may have always been the case, but at least for the rails methods we do not need to ensure the schema is loaded. For our 2 class level variables, we now load _virtual_arel without load_schema. So there is no reason to wait for schema_load. - virtual_attribute?: - has attribute loads the schema if necessary - column_for_attribute loads the schema if necessary - attribute_supported_by_sql? - has_attribute loads the schema if necessary - virtual_attribute? loads the schema indirectly (by 2 internal methods) - _virtual_arel is populated on class load, not schema load - virtual_includes - _virtual_includes is populated on class load, not schema load
1 parent 25b9b53 commit c0a87f8

File tree

3 files changed

+0
-3
lines changed

3 files changed

+0
-3
lines changed

lib/active_record/virtual_attributes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def virtual_attribute(name, type, uses: nil, arel: nil, **options)
7272
#
7373

7474
def virtual_attribute?(name)
75-
load_schema
7675
has_attribute?(name) && (
7776
!respond_to?(:column_for_attribute) ||
7877
column_for_attribute(name).kind_of?(ActiveRecord::ConnectionAdapters::NullColumn)

lib/active_record/virtual_attributes/virtual_arel.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def arel_table
8383
# - it is an attribute that is non virtual
8484
# - it is an attribute that is virtual and has arel defined
8585
def attribute_supported_by_sql?(name)
86-
load_schema
8786
try(:attribute_alias?, name) ||
8887
(has_attribute?(name) && (!virtual_attribute?(name) || !!_virtual_arel[name.to_s]))
8988
end

lib/active_record/virtual_attributes/virtual_includes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module VirtualIncludes
1818

1919
module ClassMethods
2020
def virtual_includes(name)
21-
load_schema
2221
_virtual_includes[name.to_s]
2322
end
2423

0 commit comments

Comments
 (0)