diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-06-11 16:54:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-06-11 16:54:48 +0000 |
commit | 32464f491251a609d3429346bc250984a2a4f9be (patch) | |
tree | 928e1b20aa3ec5ec6fa745d6a7d3074416847708 | |
parent | 0ba6ece2fdbd4d4ef1bb485bedabaff98e7e1626 (diff) | |
download | redmine-32464f491251a609d3429346bc250984a2a4f9be.tar.gz redmine-32464f491251a609d3429346bc250984a2a4f9be.zip |
Perf: don't load all projects.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11956 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/issue.rb | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index b5e76176f..bdb9582b7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -348,8 +348,7 @@ class Issue < ActiveRecord::Base if issue.new_record? issue.copy? elsif user.allowed_to?(:move_issues, issue.project) - projects = Issue.allowed_target_projects_on_move(user) - projects.include?(issue.project) && projects.size > 1 + Issue.allowed_target_projects_on_move.count > 1 end } @@ -416,7 +415,7 @@ class Issue < ActiveRecord::Base # Project and Tracker must be set before since new_statuses_allowed_to depends on it. if (p = attrs.delete('project_id')) && safe_attribute?('project_id') - if allowed_target_projects(user).collect(&:id).include?(p.to_i) + if allowed_target_projects(user).where(:id => p.to_i).exists? self.project_id = p end end @@ -1184,18 +1183,18 @@ class Issue < ActiveRecord::Base end # End ReportsController extraction - # Returns an array of projects that user can assign the issue to + # Returns a scope of projects that user can assign the issue to def allowed_target_projects(user=User.current) if new_record? - Project.all(:conditions => Project.allowed_to_condition(user, :add_issues)) + Project.where(Project.allowed_to_condition(user, :add_issues)) else self.class.allowed_target_projects_on_move(user) end end - # Returns an array of projects that user can move issues to + # Returns a scope of projects that user can move issues to def self.allowed_target_projects_on_move(user=User.current) - Project.all(:conditions => Project.allowed_to_condition(user, :move_issues)) + Project.where(Project.allowed_to_condition(user, :move_issues)) end private |