Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix polymorphic assocation with nil type N+1 false alarm issue #70

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

wendy-clio
Copy link
Contributor

@wendy-clio wendy-clio commented Jun 7, 2024

By adding a check is_polymorphic_association_without_type before publishing N+1 notification, it filters out the scenario if a record has a polymorphic association with a nil type.

@wendy-clio wendy-clio force-pushed the fix_poly_n_plus_one_false_alarm branch 4 times, most recently from 6f18633 to 091f920 Compare June 7, 2024 17:04
@wendy-clio wendy-clio requested review from a team as code owners June 7, 2024 17:04
@wendy-clio wendy-clio force-pushed the fix_poly_n_plus_one_false_alarm branch from 091f920 to 41abfe4 Compare June 7, 2024 17:05
@wendy-clio wendy-clio force-pushed the fix_poly_n_plus_one_false_alarm branch from 41abfe4 to 275c00a Compare June 10, 2024 13:53
@gavingmiller gavingmiller removed the request for review from a team June 10, 2024 14:09
Vtown121
Vtown121 previously approved these changes Jun 10, 2024
tudorbertiean
tudorbertiean previously approved these changes Jun 10, 2024
oliviawerre
oliviawerre previously approved these changes Jun 10, 2024
spec/lib/jit_preloader/preloader_spec.rb Outdated Show resolved Hide resolved
Copy link

@deanna-cooney deanna-cooney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One little nit but LGTM

@@ -18,13 +18,17 @@ def load_target
# always an N+1 query.
record.jit_n_plus_one_tracking ||= owner.jit_n_plus_one_tracking if record

if !jit_loaded && owner.jit_n_plus_one_tracking
if !jit_loaded && owner.jit_n_plus_one_tracking && !is_polymorphic_association_without_type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit for positive logic and methods returning boolean results ending with a ?.

Reading "is not an association without a type" is a little confusing at first. Perhaps polymorphic_association_has_type? and checking self.klass.present? instead? What you have here isn't wrong though, so take it or leave it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's another approach to simplify the name but may complex the logic. So I will just keep it as is.

@wendy-clio wendy-clio merged commit 92d50ad into master Jun 11, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants