Perf: don't load all projects.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11956 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
0ba6ece2fd
commit
32464f4912
@ -348,8 +348,7 @@ class Issue < ActiveRecord::Base
|
|||||||
if issue.new_record?
|
if issue.new_record?
|
||||||
issue.copy?
|
issue.copy?
|
||||||
elsif user.allowed_to?(:move_issues, issue.project)
|
elsif user.allowed_to?(:move_issues, issue.project)
|
||||||
projects = Issue.allowed_target_projects_on_move(user)
|
Issue.allowed_target_projects_on_move.count > 1
|
||||||
projects.include?(issue.project) && projects.size > 1
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,7 +415,7 @@ class Issue < ActiveRecord::Base
|
|||||||
|
|
||||||
# Project and Tracker must be set before since new_statuses_allowed_to depends on it.
|
# 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 (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
|
self.project_id = p
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1184,18 +1183,18 @@ class Issue < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
# End ReportsController extraction
|
# 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)
|
def allowed_target_projects(user=User.current)
|
||||||
if new_record?
|
if new_record?
|
||||||
Project.all(:conditions => Project.allowed_to_condition(user, :add_issues))
|
Project.where(Project.allowed_to_condition(user, :add_issues))
|
||||||
else
|
else
|
||||||
self.class.allowed_target_projects_on_move(user)
|
self.class.allowed_target_projects_on_move(user)
|
||||||
end
|
end
|
||||||
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)
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
Loading…
x
Reference in New Issue
Block a user