#73: Increatse performance for #autocomplete_to_project action
This commit is contained in:
parent
7be2d6f6bc
commit
62ff6312b4
|
@ -115,9 +115,17 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocomplete_to_project
|
def autocomplete_to_project
|
||||||
items = Project.accessible_by(current_ability, :membered) | @project.ancestors
|
items = []
|
||||||
term = Regexp.new(Regexp.escape params[:term].downcase)
|
term = params[:term].to_s.strip.downcase
|
||||||
items.select! {|e| term.match(e.name_with_owner.downcase) && e.repo.branches.count > 0}
|
condition = ["lower(concat(owners.uname, '/', projects.name)) ILIKE ?", "%#{term}%"]
|
||||||
|
[Project.accessible_by(current_ability, :membered), @project.ancestors].each do |p|
|
||||||
|
p = p.where(condition)
|
||||||
|
items.concat p.where(:owner_type => 'User').includes(:owner_user).
|
||||||
|
joins("INNER JOIN users as owners ON projects.owner_id = owners.id")
|
||||||
|
items.concat p.where(:owner_type => 'Group').includes(:owner_group).
|
||||||
|
joins("INNER JOIN groups as owners ON projects.owner_id = owners.id")
|
||||||
|
end
|
||||||
|
items = items.uniq{|i| i.id}.select{|e| e.repo.branches.count > 0}
|
||||||
render :json => json_for_autocomplete_base(items)
|
render :json => json_for_autocomplete_base(items)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,7 +137,7 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
|
|
||||||
def json_for_autocomplete_base items
|
def json_for_autocomplete_base items
|
||||||
items.collect do |project|
|
items.collect do |project|
|
||||||
hash = {"id" => project.id.to_s, "label" => project.name_with_owner, "value" => project.name_with_owner}
|
hash = {:id => project.id.to_s, :label => project.name_with_owner, :value => project.name_with_owner}
|
||||||
hash[:get_refs_url] = project_refs_list_path(project)
|
hash[:get_refs_url] = project_refs_list_path(project)
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,11 +5,15 @@ module Modules
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
belongs_to :owner_user, :class_name => 'User', :foreign_key => 'owner_id'
|
||||||
|
belongs_to :owner_group, :class_name => 'Group', :foreign_key => 'owner_id'
|
||||||
|
|
||||||
after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' }
|
after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' }
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_with_owner
|
def name_with_owner
|
||||||
"#{owner.respond_to?(:uname) ? owner.uname : owner.name}/#{self.name}"
|
o = owner_type == 'User' ? owner_user : owner_group
|
||||||
|
"#{o.respond_to?(:uname) ? o.uname : o.name}/#{self.name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue