Refactor and fix projects by_name scope. Apply case insensitive projects, repositories and platforms name uniqness validation. Apply case insensitive project search fallback. Redirect import task outnput to log file. Rename all task. Refs #112
This commit is contained in:
parent
0c0e131c98
commit
fab4aa6eb6
|
@ -7,7 +7,7 @@ class PersonalRepositoriesController < ApplicationController
|
|||
|
||||
def show
|
||||
if params[:query]
|
||||
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:project_page], :per_page => 30
|
||||
@projects = @repository.projects.recent.by_name("%#{params[:query]}%").paginate :page => params[:project_page], :per_page => 30
|
||||
else
|
||||
@projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ class ProjectsController < ApplicationController
|
|||
end.accessible_by(current_ability)
|
||||
|
||||
@projects = if params[:query]
|
||||
@projects.by_name(params[:query]).order("CHAR_LENGTH(name) ASC")
|
||||
@projects.by_name("%#{params[:query]}%").order("CHAR_LENGTH(name) ASC")
|
||||
else
|
||||
@projects
|
||||
end.paginate(:page => params[:project_page])
|
||||
|
|
|
@ -19,7 +19,7 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
def show
|
||||
if params[:query]
|
||||
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:project_page], :per_page => 30
|
||||
@projects = @repository.projects.recent.by_name("%#{params[:query]}%").paginate :page => params[:project_page], :per_page => 30
|
||||
else
|
||||
@projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ class Platform < ActiveRecord::Base
|
|||
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
|
||||
|
||||
validates :description, :presence => true, :uniqueness => true
|
||||
validates :name, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
|
||||
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
|
||||
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
|
||||
|
||||
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]}
|
||||
|
|
|
@ -16,7 +16,7 @@ class Project < ActiveRecord::Base
|
|||
has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User'
|
||||
has_many :groups, :through => :relations, :source => :object, :source_type => 'Group'
|
||||
|
||||
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ }
|
||||
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ }
|
||||
validates :owner, :presence => true
|
||||
# validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?}
|
||||
validates_attachment_size :srpm, :less_than => 500.megabytes
|
||||
|
@ -26,7 +26,7 @@ class Project < ActiveRecord::Base
|
|||
attr_readonly :name
|
||||
|
||||
scope :recent, order("name ASC")
|
||||
scope :by_name, lambda { |name| where('name like ?', "%#{ name }%") }
|
||||
scope :by_name, lambda {|name| where('projects.name ILIKE ?', name)}
|
||||
scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}}
|
||||
scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id = #{ repository_id }))") }
|
||||
scope :automateable, where("projects.id NOT IN (SELECT auto_build_lists.project_id FROM auto_build_lists)")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class ProjectImport < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
|
||||
scope :by_name, lambda {|name| where('project_imports.name ILIKE ?', name)}
|
||||
|
||||
after_initialize lambda {|r| r.file_mtime ||= Time.current - 10.years } # default
|
||||
end
|
||||
|
|
|
@ -13,8 +13,7 @@ class ProjectToRepository < ActiveRecord::Base
|
|||
protected
|
||||
|
||||
def one_project_in_platform_repositories
|
||||
c = Platform.scoped.select('projects.*').joins(:repositories => :projects).where(
|
||||
:projects => {:name => project.name}, :id => repository.platform_id).count
|
||||
errors.add(:project, 'should be one in platform') if c > 0
|
||||
errors.add(:project, 'should be one in platform') if Project.joins(:repositories => :platform).
|
||||
where('platforms.id = ?', repository.platform_id).by_name(project.name).count > 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class Repository < ActiveRecord::Base
|
|||
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
|
||||
|
||||
validates :description, :uniqueness => {:scope => :platform_id}, :presence => true
|
||||
validates :name, :uniqueness => {:scope => :platform_id}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ }
|
||||
validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ }
|
||||
# validates :platform_id, :presence => true # if you uncomment this platform clone will not work
|
||||
|
||||
scope :recent, order("name ASC")
|
||||
|
|
|
@ -13,10 +13,11 @@ every 5.minutes do
|
|||
end
|
||||
|
||||
every 1.day, :at => '4:00 am' do
|
||||
rake "import:sync:all" # RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=main
|
||||
rake "import:sync:all REPOSITORY=contrib" # RELEASE=official/2011 PLATFORM=mandriva2011
|
||||
rake "import:sync:all REPOSITORY=non-free" # RELEASE=official/2011 PLATFORM=mandriva2011
|
||||
rake "import:sync:all RELEASE=devel/cooker PLATFORM=cooker" # REPOSITORY=main
|
||||
rake "import:sync:all RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=contrib"
|
||||
rake "import:sync:all RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=non-free"
|
||||
rake "import:sync:all > log/sync.log"
|
||||
# rake "import:sync:run" # RELEASE=official/2011 PLATFORM=mandriva2011 REPOSITORY=main
|
||||
# rake "import:sync:run REPOSITORY=contrib" # RELEASE=official/2011 PLATFORM=mandriva2011
|
||||
# rake "import:sync:run REPOSITORY=non-free" # RELEASE=official/2011 PLATFORM=mandriva2011
|
||||
# rake "import:sync:run RELEASE=devel/cooker PLATFORM=cooker" # REPOSITORY=main
|
||||
# rake "import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=contrib"
|
||||
# rake "import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=non-free"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class AddIndexForProjectsName < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_index :projects, :name
|
||||
add_index :project_imports, :name
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_index :projects, :name
|
||||
remove_index :project_imports, :name
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120124101727) do
|
||||
ActiveRecord::Schema.define(:version => 20120127234602) do
|
||||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
|
@ -230,6 +230,8 @@ ActiveRecord::Schema.define(:version => 20120124101727) do
|
|||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "project_imports", ["name"], :name => "index_project_imports_on_name"
|
||||
|
||||
create_table "project_to_repositories", :force => true do |t|
|
||||
t.integer "project_id"
|
||||
t.integer "repository_id"
|
||||
|
@ -255,6 +257,7 @@ ActiveRecord::Schema.define(:version => 20120124101727) do
|
|||
end
|
||||
|
||||
add_index "projects", ["category_id"], :name => "index_projects_on_category_id"
|
||||
add_index "projects", ["name"], :name => "index_projects_on_name"
|
||||
|
||||
create_table "relations", :force => true do |t|
|
||||
t.integer "object_id"
|
||||
|
|
|
@ -36,7 +36,8 @@ module Grack
|
|||
uname, name = @env['PATH_INFO'].split('/')[1,2]
|
||||
name.gsub! /\.git$/, ''
|
||||
owner = User.find_by_uname(uname) || Group.find_by_uname(uname)
|
||||
Project.where(:owner_id => owner.id, :owner_type => owner.class).find_by_name(name)
|
||||
scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class)
|
||||
scoped.find_by_name(name) || scoped.by_name(name).first
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,17 @@ namespace :import do
|
|||
end
|
||||
|
||||
namespace :sync do
|
||||
task :all => [:rsync, :parse]
|
||||
desc "Sync all repos"
|
||||
task :all do
|
||||
system("bundle exec rake import:sync:run")
|
||||
system("bundle exec rake import:sync:run REPOSITORY=contrib")
|
||||
system("bundle exec rake import:sync:run REPOSITORY=non-free")
|
||||
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker")
|
||||
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=contrib")
|
||||
system("bundle exec rake import:sync:run RELEASE=devel/cooker PLATFORM=cooker REPOSITORY=non-free")
|
||||
end
|
||||
|
||||
task :run => [:rsync, :parse]
|
||||
|
||||
desc "Rsync with mirror.yandex.ru"
|
||||
task :rsync => :environment do
|
||||
|
@ -58,12 +68,13 @@ namespace :import do
|
|||
say "=== Processing '#{srpm_file}'..."
|
||||
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? and
|
||||
version = `rpm -q --qf '[%{Version}]' -p #{srpm_file}` and $?.success? and version.present?
|
||||
project_import = ProjectImport.find_or_initialize_by_name name
|
||||
project_import = ProjectImport.find_by_name(name) || ProjectImport.by_name(name).first || ProjectImport.new(:name => name)
|
||||
if version != project_import.version.to_s and File.mtime(srpm_file) > project_import.file_mtime
|
||||
unless project = project_import.project
|
||||
if project = repository.projects.find_by_name(name)
|
||||
if project = repository.projects.find_by_name(name) || repository.projects.by_name(name).first # fallback to speedup
|
||||
say "Found project '#{project.owner.uname}/#{project.name}'"
|
||||
elsif project = Project.where(:name => name, :owner_id => owner.id, :owner_type => owner.class.to_s).first
|
||||
elsif scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) and
|
||||
project = scoped.find_by_name(name).first || scoped.by_name(name).first
|
||||
repository.projects << project
|
||||
say "Add project '#{project.owner.uname}/#{project.name}' to '#{platform.name}/#{repository.name}'"
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue