Skip to content

Commit 0558568

Browse files
committed
Improve index usability for Project#project_condition (#38198).
Patch by Holger Just. git-svn-id: https://svn.redmine.org/redmine/trunk@22069 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent 9d65eee commit 0558568

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

app/models/project.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,17 @@ def commit_logtime_activity
329329
# Returns a :conditions SQL string that can be used to find the issues associated with this project.
330330
#
331331
# Examples:
332-
# project.project_condition(true) => "(projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 10))"
332+
# project.project_condition(true) => "(projects.lft >= 1 AND projects.rgt <= 10)"
333333
# project.project_condition(false) => "projects.id = 1"
334334
def project_condition(with_subprojects)
335-
cond = "#{Project.table_name}.id = #{id}"
336335
if with_subprojects
337-
cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND " \
338-
"#{Project.table_name}.rgt < #{rgt}))"
336+
"(" \
337+
"#{Project.table_name}.lft >= #{lft} AND " \
338+
"#{Project.table_name}.rgt <= #{rgt}" \
339+
")"
340+
else
341+
"#{Project.table_name}.id = #{id}"
339342
end
340-
cond
341343
end
342344

343345
def self.find(*args)

0 commit comments

Comments
 (0)