java-topology/defects/rails/patch/rails-0011-time-zone-conversion-skip-list-set.patch

33 lines
1.7 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UNDF: UNDF-2026-000000250
Fixes rails-0011: TimeZoneConversion — skip_time_zone_conversion_for_attributes Array#include? O(M×C×S) during schema load.
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ DEFECT rails-0011: lines 83-88
def create_time_zone_conversion_attribute?(name, cast_type)
- enabled_for_column = time_zone_aware_attributes &&
- !skip_time_zone_conversion_for_attributes.include?(name.to_sym) # O(S) per column
-
- enabled_for_column && time_zone_aware_types.include?(cast_type.type) # O(T) per column
+ @skip_tz_set ||= skip_time_zone_conversion_for_attributes.to_set # FIX: O(1) include?
+ @tz_types_set ||= time_zone_aware_types.to_set # FIX: O(1) include?
+ enabled_for_column = time_zone_aware_attributes &&
+ !@skip_tz_set.include?(name.to_sym)
+
+ enabled_for_column && @tz_types_set.include?(cast_type.type)
end
# NOTE: @skip_tz_set and @tz_types_set must be invalidated when the class_attributes are reassigned.
# Add a custom setter or hook into class_attribute to reset the cache:
#
# def skip_time_zone_conversion_for_attributes=(value)
# @skip_tz_set = nil
# super
# end
# BEFORE: skip_time_zone_conversion_for_attributes.include? is Array#include? O(S) per column
# Called C times per model class, M model classes: O(M×C×S) total at boot
# AFTER: @skip_tz_set is a memoized Set per class: O(1) per column → O(M×C) total
# Speedup: ~S× at M=100 models, C=50 columns, S=20 skip-list entries