From a452df79b825ada7dfa84971250cfe866b073752 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 11 Dec 2012 19:48:16 +0600 Subject: [PATCH] [refs #762] refactoring --- .../platforms/repositories_controller.rb | 38 +++++++++---------- app/models/mass_build.rb | 4 +- config/locales/models/mass_build.en.yml | 1 - config/locales/models/mass_build.ru.yml | 1 - ...121412_remove_rep_names_from_mass_build.rb | 5 +++ db/migrate/20121211132948_add_indexes.rb | 6 +++ db/schema.rb | 7 +++- 7 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 db/migrate/20121211121412_remove_rep_names_from_mass_build.rb create mode 100644 db/migrate/20121211132948_add_indexes.rb diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index 059a45a53..f197e0608 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -112,29 +112,27 @@ class Platforms::RepositoriesController < Platforms::BaseController sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc' order = "#{colName[sort_col.to_i]} #{sort_dir}" - if params[:text] == 'true' - render :text => @repository.projects.map(&:name).join("\n") + render(:text => @repository.projects.map(&:name).join("\n")) && return if params[:text] == 'true' + + if params[:added] == "true" + @projects = @repository.projects else - if params[:added] == "true" - @projects = @repository.projects - else - @projects = Project.joins(owner_subquery).addable_to_repository(@repository.id) - @projects = @projects.by_visibilities('open') if @repository.platform.platform_type == 'main' - end - @projects = @projects.paginate( - :page => (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1, - :per_page => params[:iDisplayLength].present? ? params[:iDisplayLength] : 25 - ) + @projects = Project.joins(owner_subquery).addable_to_repository(@repository.id) + @projects = @projects.by_visibilities('open') if @repository.platform.platform_type == 'main' + end + @projects = @projects.paginate( + :page => (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1, + :per_page => params[:iDisplayLength].present? ? params[:iDisplayLength] : 25 + ) - @total_projects = @projects.count - @projects = @projects.search(params[:sSearch]).search_order if params[:sSearch].present? - @projects = @projects.order(order) + @total_projects = @projects.count + @projects = @projects.search(params[:sSearch]).search_order if params[:sSearch].present? + @projects = @projects.order(order) - respond_to do |format| - format.json { - render :partial => (params[:added] == "true") ? 'project' : 'proj_ajax', :layout => false - } - end + respond_to do |format| + format.json { + render :partial => (params[:added] == "true") ? 'project' : 'proj_ajax', :layout => false + } end end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 20f26cd2a..1342eaf59 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -24,7 +24,6 @@ class MassBuild < ActiveRecord::Base :build_error ] - # ATTENTION: repositories and arches must be set before calling this method! def build_all # later with resque arches_list = arches ? Arch.where(:id => arches) : Arch.all @@ -34,8 +33,7 @@ class MassBuild < ActiveRecord::Base next if name.blank? name.chomp!; name.strip! - if project = Project.joins(:repositories).where(:name => name) - .where('repositories.id in (?)', platform.repository_ids).first + if project = Project.joins(:repositories).where('repositories.id in (?)', platform.repository_ids).find_by_name(name) begin return if self.reload.stop_build arches_list.each do |arch| diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index f160515f5..7724effbf 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -22,4 +22,3 @@ en: user: User auto_publish: Auto Publish repositories: Repositories - rep_names: Repositories diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index 923c128dc..bd478e18a 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -22,4 +22,3 @@ ru: user: Пользователь auto_publish: Авто Публикация repositories: Репозитории - rep_names: Репозитории diff --git a/db/migrate/20121211121412_remove_rep_names_from_mass_build.rb b/db/migrate/20121211121412_remove_rep_names_from_mass_build.rb new file mode 100644 index 000000000..c24d6021f --- /dev/null +++ b/db/migrate/20121211121412_remove_rep_names_from_mass_build.rb @@ -0,0 +1,5 @@ +class RemoveRepNamesFromMassBuild < ActiveRecord::Migration + def change + remove_column :mass_builds, :rep_names + end +end diff --git a/db/migrate/20121211132948_add_indexes.rb b/db/migrate/20121211132948_add_indexes.rb new file mode 100644 index 000000000..8357e4b19 --- /dev/null +++ b/db/migrate/20121211132948_add_indexes.rb @@ -0,0 +1,6 @@ +class AddIndexes < ActiveRecord::Migration + def change + add_index :project_to_repositories, [:repository_id, :project_id], :unique => true + add_index :repositories, :platform_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 05c811032..81f5cc892 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 => 20121206143724) do +ActiveRecord::Schema.define(:version => 20121211132948) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -250,7 +250,6 @@ ActiveRecord::Schema.define(:version => 20121206143724) do 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.string "rep_names" t.boolean "stop_build", :default => false, :null => false t.text "projects_list" t.integer "missed_projects_count", :default => 0, :null => false @@ -330,6 +329,8 @@ ActiveRecord::Schema.define(:version => 20121206143724) do t.datetime "updated_at", :null => false end + add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true + create_table "projects", :force => true do |t| t.string "name" t.datetime "created_at", :null => false @@ -403,6 +404,8 @@ ActiveRecord::Schema.define(:version => 20121206143724) do t.boolean "publish_without_qa", :default => true end + add_index "repositories", ["platform_id"], :name => "index_repositories_on_platform_id" + create_table "settings_notifiers", :force => true do |t| t.integer "user_id", :null => false t.boolean "can_notify", :default => true