Project

General

Profile

Patch #23196 ยป 0001-Eliminate-subselect-in-Project.allowed_to_condition-.patch

Jan from Planio www.plan.io, 2016-06-29 15:37

View differences:

app/models/project.rb
181 181
    base_statement = (perm && perm.read? ? "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED}" : "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}")
182 182
    if perm && perm.project_module
183 183
      # If the permission belongs to a project module, make sure the module is enabled
184
      base_statement << " AND #{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')"
184
      project_ids_with_module_enabled = EnabledModule.where(name: perm.project_module).pluck(:project_id)
185
      if project_ids_with_module_enabled.present?
186
        base_statement << " AND #{Project.table_name}.id IN (#{project_ids_with_module_enabled.join ','})"
187
      else
188
        base_statement << " AND 1=0"
189
      end
185 190
    end
186 191
    if project = options[:project]
187 192
      project_statement = project.project_condition(options[:with_subprojects])
    (1-1/1)