Speed up segment history CSV export
Speed up segment history CSV export

Turns out calling

    @run.segments.includes(:histories).each do |segment|
      segment.histories.find_by(attempt_number: attempt number)
      ...
    end

actually still runs n+1 queries for n segments regardless of the fact
that we're pulling all that segment's histories down first with
includes. Damn you, sometimes-surprising hidden Rails magic.

Speeds up this endpoint by a factor of (# segments) * (# attempts).

glacials/splits-io,BatedUrGonnaDie/splits-io,glacials/splits-io,BatedUrGonnaDie/splits-io,glacials/splits-io,BatedUrGonnaDie/splits-io,glacials/splits-io,BatedUrGonnaDie/splits-io