diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 4018bb7a7..a38c9e1d1 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -142,21 +142,6 @@ class BuildList < ActiveRecord::Base state_machine :status, initial: :waiting_for_response do - # WTF? around_transition -> infinite loop - before_transition do |build_list, transition| - status = HUMAN_STATUSES[build_list.status] - if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status) - MassBuild.decrement_counter "#{status.to_s}_count", build_list.mass_build_id - end - end - - after_transition do |build_list, transition| - status = HUMAN_STATUSES[build_list.status] - if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status) - MassBuild.increment_counter "#{status.to_s}_count", build_list.mass_build_id - end - end - after_transition(on: :place_build) do |build_list, transition| build_list.add_job_to_abf_worker_queue if build_list.external_nodes.blank? end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 02ed2c482..f54ba6e11 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -87,6 +87,12 @@ class MassBuild < ActiveRecord::Base end later :publish_test_failed_builds, queue: :clone_build + COUNT_STATUSES.each do |stat| + define_method "#{stat}_count" do + build_lists.where(status: BuildList::HUMAN_STATUSES.key(stat)).count + end if stat != :build_lists + end + private def generate_list(status) diff --git a/app/views/platforms/mass_builds/index.html.haml b/app/views/platforms/mass_builds/index.html.haml index 9a450a7dd..00498b6c6 100644 --- a/app/views/platforms/mass_builds/index.html.haml +++ b/app/views/platforms/mass_builds/index.html.haml @@ -19,11 +19,11 @@ %td.min_width_120 - MassBuild::COUNT_STATUSES.each do |status| = link_to t("layout.build_lists.statuses.#{status}") + ": ", build_lists_path(filter: {mass_build_id: mass_build.id, ownership: 'everything'}.merge(status != :build_lists ? {status: BuildList.status_by_human(status)} : {})) - = mass_build.read_attribute "#{status}_count" + = mass_build.send "#{status}_count" .both -if mass_build.projects_list.present? =link_to_list @platform, mass_build, 'missed_projects_list' - = mass_build.read_attribute 'missed_projects_count' + = mass_build.send 'missed_projects_count' %td - if mass_build.projects_list.present? = link_to_list @platform, mass_build, 'projects_list' diff --git a/db/migrate/20140224133747_add_mass_build_index_to_build_list.rb b/db/migrate/20140224133747_add_mass_build_index_to_build_list.rb new file mode 100644 index 000000000..269e7bc63 --- /dev/null +++ b/db/migrate/20140224133747_add_mass_build_index_to_build_list.rb @@ -0,0 +1,5 @@ +class AddMassBuildIndexToBuildList < ActiveRecord::Migration + def change + add_index :build_lists, [:mass_build_id, :status] + end +end diff --git a/db/migrate/20140224134012_remove_counters_from_mass_build.rb b/db/migrate/20140224134012_remove_counters_from_mass_build.rb new file mode 100644 index 000000000..d0e54c59b --- /dev/null +++ b/db/migrate/20140224134012_remove_counters_from_mass_build.rb @@ -0,0 +1,21 @@ +class RemoveCountersFromMassBuild < ActiveRecord::Migration + def up + remove_columns :mass_builds, :build_published_count, + :build_pending_count, + :build_started_count, + :build_publish_count, + :build_error_count, + :success_count, + :build_canceled_count + end + + def down + add_column :mass_builds, :build_published_count, :integer, default: 0 + add_column :mass_builds, :build_pending_count, :integer, default: 0 + add_column :mass_builds, :build_started_count, :integer, default: 0 + add_column :mass_builds, :build_publish_count, :integer, default: 0 + add_column :mass_builds, :build_error_count, :integer, default: 0 + add_column :mass_builds, :success_count, :integer, default: 0 + add_column :mass_builds, :build_canceled_count, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 4fc08f65c..9cb057529 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140219191644) do +ActiveRecord::Schema.define(:version => 20140224134012) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -149,6 +149,7 @@ ActiveRecord::Schema.define(:version => 20140219191644) do add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id" add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id" add_index "build_lists", ["project_id", "save_to_repository_id", "build_for_platform_id", "arch_id"], :name => "maintainer_search_index" + add_index "build_lists", ["mass_build_id", "status"], :name => "index_build_lists_on_mass_build_id_and_status" add_index "build_lists", ["project_id"], :name => "index_build_lists_on_project_id" create_table "comments", :force => true do |t| @@ -285,18 +286,11 @@ ActiveRecord::Schema.define(:version => 20140219191644) do t.integer "user_id" t.boolean "auto_publish", :default => false, :null => false t.integer "build_lists_count", :default => 0, :null => false - t.integer "build_published_count", :default => 0, :null => false - t.integer "build_pending_count", :default => 0, :null => false - t.integer "build_started_count", :default => 0, :null => false - t.integer "build_publish_count", :default => 0, :null => false - t.integer "build_error_count", :default => 0, :null => false t.boolean "stop_build", :default => false, :null => false t.text "projects_list" t.integer "missed_projects_count", :default => 0, :null => false t.text "missed_projects_list" t.boolean "new_core", :default => true - t.integer "success_count", :default => 0, :null => false - t.integer "build_canceled_count", :default => 0, :null => false t.integer "save_to_platform_id", :null => false t.text "extra_repositories" t.text "extra_build_lists"