Save 1 query + 1 cache hit in #shared_versions for root projects.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5243 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
1191be519d
commit
d022da5dd5
|
@ -379,15 +379,17 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
# Returns a scope of the Versions used by the project
|
# Returns a scope of the Versions used by the project
|
||||||
def shared_versions
|
def shared_versions
|
||||||
@shared_versions ||=
|
@shared_versions ||= begin
|
||||||
|
r = root? ? self : root
|
||||||
Version.scoped(:include => :project,
|
Version.scoped(:include => :project,
|
||||||
:conditions => "#{Project.table_name}.id = #{id}" +
|
:conditions => "#{Project.table_name}.id = #{id}" +
|
||||||
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
|
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
|
||||||
" #{Version.table_name}.sharing = 'system'" +
|
" #{Version.table_name}.sharing = 'system'" +
|
||||||
" OR (#{Project.table_name}.lft >= #{root.lft} AND #{Project.table_name}.rgt <= #{root.rgt} AND #{Version.table_name}.sharing = 'tree')" +
|
" OR (#{Project.table_name}.lft >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" +
|
||||||
" OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
|
" OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
|
||||||
" OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
|
" OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
|
||||||
"))")
|
"))")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a hash of project users grouped by role
|
# Returns a hash of project users grouped by role
|
||||||
|
|
Loading…
Reference in New Issue