java-topology/defects/rails/patch/rails-0001-preloader-batch-set.patch

19 lines
1 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-000000241
Fixes rails-0001: ActiveRecord Preloader::Batch — future_tables Array#include? inside loaders.reject loop.
--- a/activerecord/lib/active_record/associations/preloader/batch.rb
+++ b/activerecord/lib/active_record/associations/preloader/batch.rb
@@ DEFECT rails-0001: line 20-24
until branches.empty?
future_tables = branches.flat_map do |branch|
branch.future_classes - branch.runnable_loaders.map(&:klass)
- end.map(&:table_name).uniq # Array — O(F) include?
+ end.map(&:table_name).to_set # FIX: Set for O(1) include?
target_loaders = loaders.reject { |l| future_tables.include?(l.table_name) } # O(L) × O(1) — fixed
# BEFORE: future_tables is Array; loaders.reject calls Array#include? → O(L×F) per batch round-trip
# AFTER: future_tables is Set; loaders.reject calls Set#include? → O(L) per batch round-trip
# With D-depth association trees: O(D×L×F) → O(D×L)