Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

only calculate offset index once. #12537

  • Loading branch information...
commit 19b871a0902c4ec3e460a38f41583a7855edd81a 1 parent 828134b
@tenderlove tenderlove authored
View
16 activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -35,6 +35,15 @@ def associated_records_by_owner(preloader)
}
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
+ }
+ end
+
through_records.each_with_object({}) { |(lhs,center),records_by_owner|
pl_to_middle = center.group_by { |record| middle_to_pl[record] }
@@ -43,12 +52,7 @@ def associated_records_by_owner(preloader)
r.send(source_reflection.name)
}.compact
- loaded_records = pl.preloaded_records
- i = 0
- record_index = loaded_records.each_with_object({}) { |r,indexes|
- indexes[r] = i
- i += 1
- }
+ record_index = pl_indexes[pl]
records = rhs_records.sort_by { |rhs| record_index[rhs] }
@preloaded_records.concat rhs_records
records
Please sign in to comment.
Something went wrong with that request. Please try again.