Skip to content

Conversation

buk
Copy link

@buk buk commented Aug 12, 2013

Hi Jeff,

thank you for reviewing and commenting my stuff!

network.shows.each do |show|
puts show
end
network.shows.where(day_of_week: weekday).each do |show|
Copy link
Member

Choose a reason for hiding this comment

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

This will actually execute many queries (1 query for each show, for each network). It's what's called a n+1 query, and a frequent performance problem.

Instead, you could:

Show.where(day_of_week: weekday).each do |show|
  puts show
end

After all, we don't need to group by the network at all here.

@jwo
Copy link
Member

jwo commented Aug 12, 2013

Things look good!

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.

2 participants