# HG changeset patch # User Marcel Hlopko # Date 1447769138 -3600 # Node ID 8050d8d3681ff7fbe5fd7817815b6de848d6996e # Parent 7ce8706b1ea5342b79e6a08d6a2c228bd651cb7b Optimize CompareController#filter diff -r 7ce8706b1ea5 -r 8050d8d3681f web/app/helpers/settings/benchmark_configurations_helper.rb --- a/web/app/helpers/settings/benchmark_configurations_helper.rb Tue Nov 17 15:02:56 2015 +0100 +++ b/web/app/helpers/settings/benchmark_configurations_helper.rb Tue Nov 17 15:05:38 2015 +0100 @@ -1,7 +1,8 @@ module Settings::BenchmarkConfigurationsHelper def all_configurations_for(compare_query) - BenchmarkConfiguration.for_benchmark_infos(compare_query.filtered_benchmark_info_ids) + BenchmarkConfiguration + .for_benchmark_infos(compare_query.filtered_benchmark_info_ids) end def all_configurations_options diff -r 7ce8706b1ea5 -r 8050d8d3681f web/app/models/benchmark_info.rb --- a/web/app/models/benchmark_info.rb Tue Nov 17 15:02:56 2015 +0100 +++ b/web/app/models/benchmark_info.rb Tue Nov 17 15:05:38 2015 +0100 @@ -19,11 +19,10 @@ end def latest_result_for_configuration(configuration) - benchmark_results. - for_configuration_id(configuration.id). - with_batch_and_duration_preloaded. - newest_first. - first + benchmark_results + .select { |r| r.benchmark_batch.benchmark_configuration_id == configuration.id } + .sort { |r, s| r.performed_at <=> s.performed_at } + .first end end diff -r 7ce8706b1ea5 -r 8050d8d3681f web/app/models/benchmark_result.rb --- a/web/app/models/benchmark_result.rb Tue Nov 17 15:02:56 2015 +0100 +++ b/web/app/models/benchmark_result.rb Tue Nov 17 15:05:38 2015 +0100 @@ -5,19 +5,6 @@ has_many :benchmark_durations, dependent: :destroy, inverse_of: :benchmark_result has_many :benchmark_parameters, dependent: :destroy, inverse_of: :benchmark_result - scope :for_configuration_id, -> (configuration_id) do - joins(:benchmark_batch). - where("benchmark_batches.benchmark_configuration_id = ?", configuration_id) - end - - scope :with_batch_and_duration_preloaded, -> do - includes(:benchmark_batch, :benchmark_durations) - end - - scope :newest_first, -> do - order("benchmark_batches.performed_at desc, benchmark_batches.created_at desc") - end - def average_duration sum = benchmark_durations.inject(0) { |acc, val| acc += val.duration } sum / benchmark_durations.size diff -r 7ce8706b1ea5 -r 8050d8d3681f web/app/models/compare_query.rb --- a/web/app/models/compare_query.rb Tue Nov 17 15:02:56 2015 +0100 +++ b/web/app/models/compare_query.rb Tue Nov 17 15:05:38 2015 +0100 @@ -10,11 +10,15 @@ end def filtered_benchmark_infos - BenchmarkInfo.where(id: filtered_benchmark_info_ids) + BenchmarkInfo + .where(id: filtered_benchmark_info_ids) + .includes(benchmark_results: [ :benchmark_batch, + :benchmark_durations, + :benchmark_parameters ]) end def filtered_benchmark_info_ids - benchmark_infos.compact + benchmark_infos.select(&:present?).compact end end diff -r 7ce8706b1ea5 -r 8050d8d3681f web/app/views/index/_compare_table.html.erb --- a/web/app/views/index/_compare_table.html.erb Tue Nov 17 15:02:56 2015 +0100 +++ b/web/app/views/index/_compare_table.html.erb Tue Nov 17 15:05:38 2015 +0100 @@ -7,21 +7,21 @@ <% benchmark_infos.each_with_index do |benchmark_info, index| %> <% latest_result = benchmark_info.latest_result_for_configuration(bc) %> -
-
-
-
+
+
+
+
- <% end %> - - <% end %> + <% end %> + + <% end %> -
+
diff -r 7ce8706b1ea5 -r 8050d8d3681f web/app/views/settings/benchmark_configurations/show.html.erb --- a/web/app/views/settings/benchmark_configurations/show.html.erb Tue Nov 17 15:02:56 2015 +0100 +++ b/web/app/views/settings/benchmark_configurations/show.html.erb Tue Nov 17 15:05:38 2015 +0100 @@ -2,7 +2,7 @@

<%= @benchmark_configuration.name %> configuration

-<%= render 'form', - benchmark_configuration: @benchmark_configuration, +<%= render 'form', + benchmark_configuration: @benchmark_configuration, heading: "Edit configuration #{@benchmark_configuration.name}" %>