diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index 365da477..17d86f34 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -4,18 +4,18 @@ class AutoCompletesController < ApplicationController def issues @issues = [] q = params[:q].to_s - query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues - if q.match(/^\d+$/) - @issues << query.visible.find_by_id(q.to_i) - end - unless q.blank? - @issues += query.visible.find(:all, + + if q.present? + query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues + + @issues |= query.visible.find_all_by_id(q.to_i) if q =~ /^\d+$/ + + @issues |= query.visible.find(:all, :limit => 10, :order => "#{Issue.table_name}.id ASC", :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE :q OR CAST(#{Issue.table_name}.id AS CHAR(13)) LIKE :q", {:q => "%#{q.downcase}%" }]) end - @issues.compact! - @issues.uniq! + render :layout => false end