Faster query.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8487 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-03 18:10:03 +00:00
parent 818988c419
commit bbe1ff3ec9
1 changed files with 19 additions and 2 deletions

View File

@ -590,6 +590,23 @@ class Query < ActiveRecord::Base
raise StatementInvalid.new(e.message) raise StatementInvalid.new(e.message)
end end
# Returns the issues ids
def issue_ids(options={})
order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
order_option = nil if order_option.blank?
joins = (order_option && order_option.include?('authors')) ? "LEFT OUTER JOIN users authors ON authors.id = #{Issue.table_name}.author_id" : nil
Issue.visible.scoped(:conditions => options[:conditions]).find_ids :include => ([:status, :project] + (options[:include] || [])).uniq,
:conditions => statement,
:order => order_option,
:joins => joins,
:limit => options[:limit],
:offset => options[:offset]
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end
# Returns the journals # Returns the journals
# Valid options are :order, :offset, :limit # Valid options are :order, :offset, :limit
def journals(options={}) def journals(options={})
@ -738,9 +755,9 @@ class Query < ActiveRecord::Base
end end
end end
when "o" when "o"
sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id" sql = "#{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_false})" if field == "status_id"
when "c" when "c"
sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id" sql = "#{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_true})" if field == "status_id"
when ">t-" when ">t-"
sql = relative_date_clause(db_table, db_field, - value.first.to_i, 0) sql = relative_date_clause(db_table, db_field, - value.first.to_i, 0)
when "<t-" when "<t-"