summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-20 20:03:22 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-20 20:03:22 +0000
commit8a8ca4036490dfb16c437b43123a5ed90585da44 (patch)
tree8a9ceeda145367431daeffa0a18d987136147884
parent03397f605c7ece40b38ebdcf49bd5e4fe9040ac8 (diff)
downloadredmine-8a8ca4036490dfb16c437b43123a5ed90585da44.tar.gz
redmine-8a8ca4036490dfb16c437b43123a5ed90585da44.zip
Prevents n SQL queries (n = project count) on cross-project issues list.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4550 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/query.rb22
-rw-r--r--test/unit/query_test.rb6
2 files changed, 18 insertions, 10 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index 7c246f9ae..949054533 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -187,10 +187,18 @@ class Query < ActiveRecord::Base
if project
user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
else
- project_ids = Project.all(:conditions => Project.visible_by(User.current)).collect(&:id)
- if project_ids.any?
- # members of the user's projects
- user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort.collect{|s| [s.name, s.id.to_s] }
+ all_projects = Project.visible.all
+ if all_projects.any?
+ # members of visible projects
+ user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", all_projects.collect(&:id)]).sort.collect{|s| [s.name, s.id.to_s] }
+
+ # project filter
+ project_values = []
+ Project.project_tree(all_projects) do |p, level|
+ prefix = (level > 0 ? ('--' * level + ' ') : '')
+ project_values << ["#{prefix}#{p.name}", p.id.to_s]
+ end
+ @available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values} unless project_values.empty?
end
end
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
@@ -225,12 +233,6 @@ class Query < ActiveRecord::Base
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => system_shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
end
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
- # project filter
- project_values = Project.all(:conditions => Project.visible_by(User.current), :order => 'lft').map do |p|
- pre = (p.level > 0 ? ('--' * p.level + ' ') : '')
- ["#{pre}#{p.name}",p.id.to_s]
- end
- @available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values}
end
@available_filters
end
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index f5d9847d6..173367a4b 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -382,6 +382,12 @@ class QueryTest < ActiveSupport::TestCase
assert users[:values].map{|u|u[1]}.include?("3")
end
+ should "include visible projects in cross-project view" do
+ projects = @query.available_filters["project_id"]
+ assert_not_nil projects
+ assert projects[:values].map{|u|u[1]}.include?("1")
+ end
+
context "'member_of_group' filter" do
should "be present" do
assert @query.available_filters.keys.include?("member_of_group")