Project

General

Profile

Patch #21611 » query_project_statement.diff

use query not pluck ids - Ondřej Ezr, 2015-12-27 19:07

View differences:

app/models/query.rb
535 535
  def project_statement
536 536
    project_clauses = []
537 537
    if project && !project.descendants.active.empty?
538
      ids = [project.id]
539 538
      if has_filter?("subproject_id")
540 539
        case operator_for("subproject_id")
541 540
        when '='
542 541
          # include the selected subprojects
543
          ids += values_for("subproject_id").each(&:to_i)
542
          ids = [project.id] + values_for("subproject_id").each(&:to_i)
543
          project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
544 544
        when '!*'
545 545
          # main project only
546
          project_clauses << "#{Project.table_name}.id = %d" % project.id
546 547
        else
547 548
          # all subprojects
548
          ids += project.descendants.collect(&:id)
549
          project_clauses << "#{Project.table_name}.lft >= #{project.lft} AND #{Project.table_name}.rgt <= #{project.rgt}"
549 550
        end
550 551
      elsif Setting.display_subprojects_issues?
551
        ids += project.descendants.collect(&:id)
552
        project_clauses << "#{Project.table_name}.lft >= #{project.lft} AND #{Project.table_name}.rgt <= #{project.rgt}"
552 553
      end
553
      project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
554 554
    elsif project
555 555
      project_clauses << "#{Project.table_name}.id = %d" % project.id
556 556
    end
(1-1/2)