web/app/models/benchmark_info.rb
author Marcel Hlopko <marcel@hlopko.com>
Mon, 16 Nov 2015 16:15:12 +0100
changeset 303 ce55fabc46a0
parent 237 195fca969b9a
child 306 8050d8d3681f
permissions -rw-r--r--
Optimize ResultsController#configuration_results

class BenchmarkInfo < ActiveRecord::Base

  has_many :benchmark_results, dependent: :destroy, inverse_of: :benchmark_info

  validates_presence_of :name, :benchmark_class, :benchmark_selector

  def self.from_json(data)
    bench_info = BenchmarkInfo.find_by(name: data["name"])
    unless bench_info
      bench_info = BenchmarkInfo.create!(
        name:               data["name"],
        benchmark_class:    data["class"],
        benchmark_selector: data["selector"],
        description:        data["description"]
      )
    end

    bench_info
  end

  def latest_result_for_configuration(configuration)
    benchmark_results.
      for_configuration_id(configuration.id).
      with_batch_and_duration_preloaded.
      newest_first.
      first
  end

end

# == Schema Information
#
# Table name: benchmark_infos
#
#  id                 :integer          not null, primary key
#  benchmark_class    :string(255)
#  benchmark_selector :string(255)
#  description        :text
#  created_at         :datetime
#  updated_at         :datetime
#  name               :string(255)
#