Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Last active August 29, 2015 14:16
Show Gist options
  • Save yuroyoro/b68f673c2ac24f0fe29a to your computer and use it in GitHub Desktop.
Save yuroyoro/b68f673c2ac24f0fe29a to your computer and use it in GitHub Desktop.
block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:45)
samples: 8 self (0.8%) / 332 total (33.3%)
callers:
332 ( 100.0%) ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (324 total):
307 ( 94.8%) block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
9 ( 2.8%) ActiveRecord::Core#hash
8 ( 2.5%) block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
code:
| 45 | through_records.each_with_object({}) { |(lhs,center),records_by_owner|
10 (1.0%) / 2 (0.2%) | 46 | pl_to_middle = center.group_by { |record| middle_to_pl[record] }
| 47 |
322 (32.3%) / 6 (0.6%) | 48 | records_by_owner[lhs] = pl_to_middle.flat_map do |pl, middles|
| 49 | rhs_records = middles.flat_map { |r|
block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:48)
samples: 4 self (0.4%) / 307 total (30.8%)
callers:
307 ( 100.0%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (303 total): [70/1966]
273 ( 90.1%) block (3 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
20 ( 6.6%) block (3 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
6 ( 2.0%) ActiveRecord::AttributeMethods#respond_to?
4 ( 1.3%) ActiveRecord::Associations::CollectionProxy#to_ary
code:
| 48 | records_by_owner[lhs] = pl_to_middle.flat_map do |pl, middles|
283 (28.4%) | 49 | rhs_records = middles.flat_map { |r|
| 50 | association = r.association source_reflection.name
| 51 |
| 52 | association.reader
| 53 | }.compact
| 54 |
24 (2.4%) / 4 (0.4%) | 55 | rhs_records.sort_by { |rhs| record_offset[rhs] }
| 56 | end
block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:46)
samples: 2 self (0.2%) / 8 total (0.8%)
callers:
8 ( 100.0%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (6 total):
6 ( 100.0%) ActiveRecord::Core#hash
code:
8 (0.8%) / 2 (0.2%) | 46 | pl_to_middle = center.group_by { |record| middle_to_pl[record] }
| 47 |
block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:26)
samples: 1 self (0.1%) / 1 total (0.1%)
callers:
1 ( 100.0%) ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
code:
1 (0.1%) / 1 (0.1%) | 26 | middle_records = through_records.flat_map { |(_,rec)| rec }
| 27 |
block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:35)
samples: 1 self (0.1%) / 7 total (0.7%)
callers:
7 ( 100.0%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (6 total):
6 ( 100.0%) ActiveRecord::Core#hash
code:
| 35 | pl.owners.each { |middle|
7 (0.7%) / 1 (0.1%) | 36 | h[middle] = pl
| 37 | }
block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:41)
samples: 1 self (0.1%) / 10 total (1.0%)
callers:
10 ( 100.0%) ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (9 total):
9 ( 100.0%) ActiveRecord::Core#hash
code:
| 41 | @preloaded_records.each_with_index do |record,i|
10 (1.0%) / 1 (0.1%) | 42 | record_offset[record] = i
| 43 | end
block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:18)
samples: 1 self (0.1%) / 328 total (32.9%)
callers:
328 ( 100.0%) ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (327 total):
305 ( 93.3%) ActiveRecord::Associations::CollectionAssociation#reader
14 ( 4.3%) ActiveRecord::Associations::Preloader::ThroughAssociation#through_reflection
5 ( 1.5%) ActiveRecord::Delegation#respond_to?
2 ( 0.6%) ActiveRecord::Associations::CollectionProxy#to_ary
1 ( 0.3%) ActiveRecord::Associations#association
code:
| 18 | through_records = owners.map do |owner|
15 (1.5%) | 19 | association = owner.association through_reflection.name
| 20 |
313 (31.4%) / 1 (0.1%) | 21 | [owner, Array(association.reader)]
| 22 | end
ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:13)
samples: 0 self (0.0%) / 1342 total (134.6%)
callers:
1342 ( 100.0%) ActiveRecord::Associations::Preloader::HasManyThrough#associated_records_by_owner
callees (1342 total):
662 ( 49.3%) ActiveRecord::Associations::Preloader#preload
332 ( 24.7%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
328 ( 24.4%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
10 ( 0.7%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
7 ( 0.5%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
1 ( 0.1%) ActiveRecord::Associations::Preloader::ThroughAssociation#reset_association
1 ( 0.1%) ActiveRecord::Associations::Preloader::ThroughAssociation#through_scope
1 ( 0.1%) block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
code:
| 13 | def associated_records_by_owner(preloader)
142 (14.2%) | 14 | preloader.preload(owners,
| 15 | through_reflection.name,
1 (0.1%) | 16 | through_scope)
| 17 |
328 (32.9%) | 18 | through_records = owners.map do |owner|
| 19 | association = owner.association through_reflection.name
| 20 |
| 21 | [owner, Array(association.reader)]
| 22 | end
| 23 |
1 (0.1%) | 24 | reset_association owners, through_reflection.name
| 25 |
1 (0.1%) | 26 | middle_records = through_records.flat_map { |(_,rec)| rec }
| 27 |
520 (52.2%) | 28 | preloaders = preloader.preload(middle_records,
| 29 | source_reflection.name,
| 30 | reflection_scope)
| 31 |
| 32 | @preloaded_records = preloaders.flat_map(&:preloaded_records)
| 33 |
7 (0.7%) | 34 | middle_to_pl = preloaders.each_with_object({}) do |pl,h|
| 35 | pl.owners.each { |middle|
| 36 | h[middle] = pl
| 37 | }
| 38 | end
| 39 |
| 40 | record_offset = {}
10 (1.0%) | 41 | @preloaded_records.each_with_index do |record,i|
| 42 | record_offset[record] = i
| 43 | end
| 44 |
332 (33.3%) | 45 | through_records.each_with_object({}) { |(lhs,center),records_by_owner|
| 46 | pl_to_middle = center.group_by { |record| middle_to_pl[record] }
block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:34)
samples: 0 self (0.0%) / 7 total (0.7%)
callers:
7 ( 100.0%) ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (7 total):
7 ( 100.0%) block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
code:
| 34 | middle_to_pl = preloaders.each_with_object({}) do |pl,h|
7 (0.7%) | 35 | pl.owners.each { |middle|
| 36 | h[middle] = pl
block (3 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:55)
samples: 0 self (0.0%) / 20 total (2.0%)
callers:
20 ( 100.0%) block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (20 total):
20 ( 100.0%) ActiveRecord::Core#hash
code:
20 (2.0%) | 55 | rhs_records.sort_by { |rhs| record_offset[rhs] }
| 56 | end
block (3 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:49)
samples: 0 self (0.0%) / 273 total (27.4%)
callers:
273 ( 100.0%) block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (273 total):
253 ( 92.7%) ActiveRecord::Associations::CollectionAssociation#reader
11 ( 4.0%) ActiveRecord::Associations::Preloader::ThroughAssociation#source_reflection
8 ( 2.9%) ActiveRecord::Associations::SingularAssociation#reader
1 ( 0.4%) ActiveRecord::Associations#association
code:
| 49 | rhs_records = middles.flat_map { |r|
12 (1.2%) | 50 | association = r.association source_reflection.name
| 51 |
261 (26.2%) | 52 | association.reader
| 53 | }.compact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment