From 08c58a84df1f2ce2b2132bc599ea669972f800aa Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Mon, 6 Aug 2012 19:35:11 +0400 Subject: [PATCH 1/5] [refs #604] Remove old build list after 3 month --- app/models/build_list.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 1349f8b6b..ed957089d 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -23,7 +23,8 @@ class BuildList < ActiveRecord::Base errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.platform_type == 'main' && save_to_platform_id != build_for_platform_id } - LIVE_TIME = 3.week + LIVE_TIME = 4.week # for unpublished + MAX_LIVE_TIME = 3.month # for published # The kernel does not send these statuses directly BUILD_CANCELED = 5000 @@ -92,7 +93,7 @@ class BuildList < ActiveRecord::Base s } scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")} - scope :outdated, where('updated_at < ? AND status <> ?', Time.now - LIVE_TIME, BUILD_PUBLISHED) + scope :outdated, where('created_at < ? AND status <> ? OR created_at < ?', Time.now - LIVE_TIME, BUILD_PUBLISHED, Time.now - MAX_LIVE_TIME) serialize :additional_repos serialize :include_repos From 69fb368911ffef411bcd4a32e009ed44292ad6c8 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Tue, 7 Aug 2012 00:48:29 +0400 Subject: [PATCH 2/5] merger stash --- app/models/project.rb | 11 +++---- db/schema.rb | 70 +++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index c69f1125e..e2c89a12c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -23,10 +23,11 @@ class Project < ActiveRecord::Base validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^#{NAME_REGEXP}$/, :message => I18n.t("activerecord.errors.project.uname")} validates :owner, :presence => true + validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, :has_issues, :has_wiki - attr_readonly :name + attr_readonly :name, :owner_id, :owner_type scope :recent, order("name ASC") scope :search_order, order("CHAR_LENGTH(name) ASC") @@ -83,13 +84,12 @@ class Project < ActiveRecord::Base owner == user end - def build_for(platform, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0) + def build_for(platform, repository_id, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0) # Select main and project platform repository(contrib, non-free and etc) # If main does not exist, will connect only project platform repository # If project platform repository is main, only main will be connect - build_reps = [platform.repositories.find_by_name('main')] - build_reps += platform.repositories.select {|rep| self.repository_ids.include? rep.id} - build_reps_ids = build_reps.compact.map(&:id).uniq + main_rep_id = platform.repositories.find_by_name('main').id + build_reps_ids = [main_rep_id, repository_id].compact.uniq arch = Arch.find_by_name(arch) if arch.acts_like?(:string) build_lists.create do |bl| bl.save_to_platform = platform @@ -103,6 +103,7 @@ class Project < ActiveRecord::Base bl.include_repos = build_reps_ids bl.priority = priority bl.mass_build_id = mass_build_id + bl.save_to_repository_id = repository_id end end diff --git a/db/schema.rb b/db/schema.rb index f9df9fb18..7a529a422 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -106,8 +106,9 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "project_version" t.integer "project_id" t.integer "arch_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "notified_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -136,8 +137,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" end @@ -154,8 +155,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "flash_notifies", :force => true do |t| @@ -167,8 +168,6 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.datetime "updated_at", :null => false end - add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false - create_table "groups", :force => true do |t| t.integer "owner_id" t.datetime "created_at", :null => false @@ -185,8 +184,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" @@ -246,14 +245,14 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "description" t.string "name", :null => false t.integer "parent_platform_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "released", :default => false, :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type", :null => false + t.string "distrib_type" end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false @@ -262,16 +261,16 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "user_id" end create_table "product_build_lists", :force => true do |t| t.integer "product_id" t.integer "status", :default => 2, :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id" @@ -309,14 +308,14 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" @@ -354,8 +353,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "actor_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "role" end @@ -384,8 +383,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -393,21 +392,20 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "users", :force => true do |t| t.string "name" - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.text "ssh_key" t.string "uname" t.string "role" - t.string "language", :default => "en" + t.string "language", :default => "en" + t.integer "own_projects_count", :default => 0, :null => false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.integer "own_projects_count", :default => 0, :null => false - t.datetime "reset_password_sent_at" t.text "professional_experience" t.string "site" t.string "company" @@ -416,11 +414,11 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" t.string "authentication_token" - t.integer "build_priority", :default => 50 + t.integer "build_priority", :default => 50 end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token" @@ -430,4 +428,4 @@ ActiveRecord::Schema.define(:version => 20120730214052) do add_index "users", ["uname"], :name => "index_users_on_uname", :unique => true add_index "users", ["unlock_token"], :name => "index_users_on_unlock_token", :unique => true -end \ No newline at end of file +end From 30efe134efbc717edea285c99ab5d72c769689cf Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Tue, 7 Aug 2012 01:07:54 +0400 Subject: [PATCH 3/5] [refs #604] Remove old and empty mass builds --- app/models/mass_build.rb | 1 + lib/tasks/buildlist.rake | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 8cdc5c0f9..4fa18720e 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -4,6 +4,7 @@ class MassBuild < ActiveRecord::Base has_many :build_lists, :dependent => :destroy scope :by_platform, lambda { |platform| where(:platform_id => platform.id) } + scope :outdated, where('created_at < ?', Time.now + 1.day - BuildList::MAX_LIVE_TIME) attr_accessor :repositories, :arches attr_accessible :repositories, :arches, :auto_publish diff --git a/lib/tasks/buildlist.rake b/lib/tasks/buildlist.rake index ea6a40eff..ee77ab158 100644 --- a/lib/tasks/buildlist.rake +++ b/lib/tasks/buildlist.rake @@ -2,15 +2,19 @@ namespace :buildlist do namespace :clear do - desc 'Remove outdated unpublished BuildLists' + desc 'Remove outdated BuildLists and MassBuilds' task :outdated => :environment do say "Removing outdated BuildLists" outdated = BuildList.outdated say "There are #{outdated.count} outdated BuildLists at #{Time.now}" - BuildList.outdated.destroy_all - say "Outdated BuildLists was successfully removed" + say "Removing outdated BuildLists" + outdated = MassBuild.outdated + say "There are #{outdated.count} outdated MassBuilds at #{Time.now}" + MassBuild.outdated.destroy_all + + say "Outdated BuildLists and MassBuilds was successfully removed" end end end From c310d3cfec0dcfaa24b04bbdd4418507f9ba0eaa Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Tue, 7 Aug 2012 01:11:46 +0400 Subject: [PATCH 4/5] [refs #604] Fix schema --- db/schema.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index b7986945c..fa167f2e8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -169,6 +169,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.datetime "updated_at", :null => false end + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false + create_table "groups", :force => true do |t| t.integer "owner_id" t.datetime "created_at", :null => false @@ -253,7 +255,7 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type" + t.string "distrib_type", :null => false end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false From ffb6d5964e1e1a2dbf8a54877b3becb1306f71af Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Tue, 7 Aug 2012 01:15:55 +0400 Subject: [PATCH 5/5] [refs #604] Fix typo --- lib/tasks/buildlist.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/buildlist.rake b/lib/tasks/buildlist.rake index ee77ab158..c22cea26d 100644 --- a/lib/tasks/buildlist.rake +++ b/lib/tasks/buildlist.rake @@ -9,7 +9,7 @@ namespace :buildlist do say "There are #{outdated.count} outdated BuildLists at #{Time.now}" BuildList.outdated.destroy_all - say "Removing outdated BuildLists" + say "Removing outdated MassBuilds" outdated = MassBuild.outdated say "There are #{outdated.count} outdated MassBuilds at #{Time.now}" MassBuild.outdated.destroy_all