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

Bug: Ensure HABTM associations are not incorrectly labeled n+1 #581

Conversation

tbro-evi
Copy link
Contributor

Fixes #546

Prior to this commit, unless your HABTM join table excluded the id
primary key column, it would be erroneously marked as a potential n+1
query. Other HABTM queries that had join tables without an id column
were properly ignored. This exclusion seems to be a side-effect of
excluding objects that don't have primary keys/id columns in an effort
to ignore non-persisted objects (stemming from this commit).

This commit, instead, explicitly ignores HABTM models when checking for potential
objects that could have a n+1 impact since they are join tables that
typically aren't queried for specifically but instead are joined on.

Prior to this commit, unless your HABTM join table excluded the `id`
primary key column, it would be erroneously marked as a potential n+1
query. Other HABTM queries that had join tables _without_ an `id` column
were properly ignored. This exclusion _seems_ to be a side-effect of
excluding objects that don't have primary keys/id columns in an effort
to ignore non-persisted objects (stemming from [this commit](https://github.com/flyerhzm/bullet/blob/2c8a6d26f4a11bc8b3af5ff7da815401049732d4/lib/bullet/detector/n_plus_one_query.rb#L37)).

This commit, instead, explicitly ignores HABTM models when checking for potential
objects that could have a n+1 impact since they are join tables that
typically aren't queried for specifically but instead are joined on.
@tbro-evi
Copy link
Contributor Author

@flyerhzm Wondering if I could get your review on this?

@flyerhzm flyerhzm merged commit e44e375 into flyerhzm:master Jun 25, 2021
@flyerhzm
Copy link
Owner

@tbro-evi looks good to me, thanks.

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.

wrong detecting HABTM association name when checking N+1
2 participants