mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
simplify populating the ordering hash
This commit is contained in:
parent
43a63f6d5e
commit
03c98bddfd
1 changed files with 5 additions and 10 deletions
|
@ -29,7 +29,7 @@ module ActiveRecord
|
|||
source_reflection.name,
|
||||
reflection_scope)
|
||||
|
||||
@preloaded_records.concat preloaders.flat_map(&:preloaded_records)
|
||||
@preloaded_records = preloaders.flat_map(&:preloaded_records)
|
||||
|
||||
middle_to_pl = preloaders.each_with_object({}) do |pl,h|
|
||||
pl.owners.each { |middle|
|
||||
|
@ -37,13 +37,9 @@ module ActiveRecord
|
|||
}
|
||||
end
|
||||
|
||||
pl_indexes = preloaders.each_with_object({}) do |pl,hash|
|
||||
i = 0
|
||||
loaded_records = pl.preloaded_records
|
||||
hash[pl] = loaded_records.each_with_object({}) { |r,indexes|
|
||||
indexes[r] = i
|
||||
i += 1
|
||||
}
|
||||
record_offset = {}
|
||||
@preloaded_records.each_with_index do |record,i|
|
||||
record_offset[record] = i
|
||||
end
|
||||
|
||||
through_records.each_with_object({}) { |(lhs,center),records_by_owner|
|
||||
|
@ -54,8 +50,7 @@ module ActiveRecord
|
|||
r.send(source_reflection.name)
|
||||
}.compact
|
||||
|
||||
record_index = pl_indexes[pl]
|
||||
rhs_records.sort_by { |rhs| record_index[rhs] }
|
||||
rhs_records.sort_by { |rhs| record_offset[rhs] }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue