diff --git a/app/models/live_result.rb b/app/models/live_result.rb index e3699061fd5..22e2ccd613d 100644 --- a/app/models/live_result.rb +++ b/app/models/live_result.rb @@ -81,7 +81,7 @@ def should_recompute? end def complete? - live_attempts.where.not(value: 0).count == round.format.expected_solve_count + live_attempts.filter { it.value != 0 }.length == round.format.expected_solve_count end def values_for_sorting diff --git a/app/models/round.rb b/app/models/round.rb index b99551fe45b..1d42c3e3b6f 100644 --- a/app/models/round.rb +++ b/app/models/round.rb @@ -229,7 +229,10 @@ def recompute_advancing missing_attempts = total_competitors - round_results.count potential_results = Array.new(missing_attempts) { LiveResult.build(round: self) } - results_with_potential = (round_results.to_a + potential_results).sort_by(&:potential_solve_time) + + # Eager load associations to avoid N+1 on potential_solve_time + loaded_results = round_results.includes(:live_attempts).to_a + results_with_potential = (loaded_results + potential_results).sort_by(&:potential_solve_time) qualifying_index = if final_round? 3