The N+1 You Already Shipped

A query that looks fine at 5 rows and dies at 5,000

Module 11 shipped BookingsController#index scoped through current_user.bookings, ordered, paged β€” and already carrying .includes(:walker, :dog). You typed that line as an exercise and moved on. This module stops and asks: what happens the moment that .includes isn't there? Not hypothetically β€” read the Rails log both ways, because an N+1 is invisible in the one place most people look (the response) and screaming in the one place almost nobody checks first (the log).

Picture index without .includes, one line changed:

bookings = current_user.bookings.order(starts_at: :asc)

booking_payload still calls booking.walker.id and booking.dog.id for every booking in the array. Each of those is a method call on an association Rails hasn't loaded yet β€” so each one fires its own SELECT, the instant it's touched.