bullet icon indicating copy to clipboard operation
bullet copied to clipboard

has_many through with order clause not being picked up as n+1

Open kbaum opened this issue 10 years ago • 7 comments

I have reproduced the issue in the following test:

https://github.com/kbaum/bullet_test/blob/master/test/unit/user_space_test.rb

For some reason, when we have the order on the has_many users, the test has an n+1.

  has_many :users, :through => :user_spaces,
    :order=>'user_spaces.position, user_spaces.id'

The problem is that bullet does not catch this n+1 for some reason. I get the following output when i run the test:

http://vts-monosnap.s3.amazonaws.com/bullet_test__bash__36285_2014-07-24_17-11-26_2014-07-24_17-12-09.jpg

thx!

-karl

kbaum avatar Jul 24 '14 21:07 kbaum

@kbaum didn't you think it's a rails bug? it already eager loads user_spaces and then load them one by one again.

flyerhzm avatar Jul 26 '14 04:07 flyerhzm

I definitely agree that it's a rails bug but was thinking it would be helpful if bullet reported all n+1 occurrences regardless of whether it's a rails bug or not.

Thx!

— Sent from Mailbox

On Sat, Jul 26, 2014 at 12:58 AM, Richard Huang [email protected] wrote:

@kbaum didn't you think it's a rails bug? it already eager loads user_spaces and then load them one by one again.

Reply to this email directly or view it on GitHub: https://github.com/flyerhzm/bullet/issues/179#issuecomment-50223482

kbaum avatar Jul 26 '14 12:07 kbaum

@kbaum in case bullet can detect such n+1 queries, how will you fix it?

flyerhzm avatar Jul 26 '14 12:07 flyerhzm

If I explicitly include user_spaces, it fixes or if I taker the order clause away from the has many through and instead order from within memory.— Sent from Mailbox

On Sat, Jul 26, 2014 at 8:13 AM, Richard Huang [email protected] wrote:

@kbaum in case bullet can detect such n+1 queries, how will you fix it?

Reply to this email directly or view it on GitHub: https://github.com/flyerhzm/bullet/issues/179#issuecomment-50232475

kbaum avatar Jul 26 '14 13:07 kbaum

@kbaum I'll try

flyerhzm avatar Jul 28 '14 03:07 flyerhzm

Thx!— Sent from Mailbox

On Sun, Jul 27, 2014 at 11:56 PM, Richard Huang [email protected] wrote:

@kbaum I'll try

Reply to this email directly or view it on GitHub: https://github.com/flyerhzm/bullet/issues/179#issuecomment-50298221

kbaum avatar Jul 28 '14 12:07 kbaum

+1

lalitkapoor avatar Nov 23 '15 20:11 lalitkapoor