-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
6f18633
to
091f920
Compare
091f920
to
41abfe4
Compare
lib/jit_preloader/active_record/associations/singular_association.rb
Outdated
Show resolved
Hide resolved
… with nil type to be include
41abfe4
to
275c00a
Compare
Co-authored-by: Olivia Werre <[email protected]>
94c257e
There was a problem hiding this 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 |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
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.