19 lines
1 KiB
Diff
19 lines
1 KiB
Diff
# 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)
|