Skip to content

Commit

Permalink
call association also on through reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Nov 17, 2023
1 parent ebc943b commit 5343444
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 97 deletions.
17 changes: 11 additions & 6 deletions lib/bullet/active_record4.rb
Expand Up @@ -107,12 +107,17 @@ def construct_association(record, join, row)
result = origin_construct_association(record, join, row)

if Bullet.start?
associations = join.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [join.reflection.name]
if join.reflection.chain?
associations << join.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(ar_parent, association)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << association
end
end

result
Expand Down
17 changes: 11 additions & 6 deletions lib/bullet/active_record41.rb
Expand Up @@ -110,12 +110,17 @@ def construct_model(record, node, row, model_cache, id, aliases)
result = origin_construct_model(record, node, row, model_cache, id, aliases)

if Bullet.start?
associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [node.reflection.name]
if node.reflection.nested?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(record, association)
Bullet::Detector::NPlusOneQuery.call_association(record, association)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << association
end
end

result
Expand Down
34 changes: 22 additions & 12 deletions lib/bullet/active_record42.rb
Expand Up @@ -129,12 +129,17 @@ def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
id = row[key]
next unless id.nil?

associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
associations = [node.reflection.name]
if node.reflection.nested?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(ar_parent, association)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << association
end
end
end
end
Expand All @@ -147,12 +152,17 @@ def construct_model(record, node, row, model_cache, id, aliases)
result = origin_construct_model(record, node, row, model_cache, id, aliases)

if Bullet.start?
associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [node.reflection.name]
if node.reflection.nested?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(record, association)
Bullet::Detector::NPlusOneQuery.call_association(record, association)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << association
end
end

result
Expand Down
34 changes: 22 additions & 12 deletions lib/bullet/active_record5.rb
Expand Up @@ -138,12 +138,17 @@ def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
id = row[key]
next unless id.nil?

associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(ar_parent, association)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << association
end
end
end
end
Expand All @@ -156,12 +161,17 @@ def construct_model(record, node, row, model_cache, id, aliases)
result = super

if Bullet.start?
associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(record, association)
Bullet::Detector::NPlusOneQuery.call_association(record, association)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << association
end
end

result
Expand Down
34 changes: 22 additions & 12 deletions lib/bullet/active_record52.rb
Expand Up @@ -101,12 +101,17 @@ def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
id = row[key]
next unless id.nil?

associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(ar_parent, association)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << association
end
end
end
end
Expand All @@ -119,12 +124,17 @@ def construct_model(record, node, row, model_cache, id, aliases)
result = super

if Bullet.start?
associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(record, association)
Bullet::Detector::NPlusOneQuery.call_association(record, association)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << association
end
end

result
Expand Down
34 changes: 22 additions & 12 deletions lib/bullet/active_record60.rb
Expand Up @@ -128,12 +128,17 @@ def construct(ar_parent, parent, row, seen, model_cache)
id = row[key]
next unless id.nil?

associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(ar_parent, association)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << association
end
end
end
end
Expand All @@ -146,12 +151,17 @@ def construct_model(record, node, row, model_cache, id)
result = super

if Bullet.start?
associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(record, association)
Bullet::Detector::NPlusOneQuery.call_association(record, association)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << association
end
end

result
Expand Down
34 changes: 22 additions & 12 deletions lib/bullet/active_record61.rb
Expand Up @@ -128,12 +128,17 @@ def construct(ar_parent, parent, row, seen, model_cache, strict_loading_value)
id = row[key]
next unless id.nil?

associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(ar_parent, association)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << association
end
end
end
end
Expand All @@ -146,12 +151,17 @@ def construct_model(record, node, row, model_cache, id, strict_loading_value)
result = super

if Bullet.start?
associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(record, association)
Bullet::Detector::NPlusOneQuery.call_association(record, association)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << association
end
end

result
Expand Down
34 changes: 22 additions & 12 deletions lib/bullet/active_record70.rb
Expand Up @@ -137,12 +137,17 @@ def construct(ar_parent, parent, row, seen, model_cache, strict_loading_value)
id = row[key]
next unless id.nil?

associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(ar_parent, association)
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
@bullet_eager_loadings[ar_parent.class] ||= {}
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
@bullet_eager_loadings[ar_parent.class][ar_parent] << association
end
end
end
end
Expand All @@ -155,12 +160,17 @@ def construct_model(record, node, row, model_cache, id, strict_loading_value)
result = super

if Bullet.start?
associations = node.reflection.name
Bullet::Detector::Association.add_object_associations(record, associations)
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << associations
associations = [node.reflection.name]
if node.reflection.through_reflection?
associations << node.reflection.through_reflection.name
end
associations.each do |association|
Bullet::Detector::Association.add_object_associations(record, association)
Bullet::Detector::NPlusOneQuery.call_association(record, association)
@bullet_eager_loadings[record.class] ||= {}
@bullet_eager_loadings[record.class][record] ||= Set.new
@bullet_eager_loadings[record.class][record] << association
end
end

result
Expand Down

0 comments on commit 5343444

Please sign in to comment.