Commit 0108cdf4 authored by Douwe Maan's avatar Douwe Maan

Improve performance of filtering issues by milestone

parent 9127ae5c
...@@ -74,11 +74,11 @@ class IssuableFinder ...@@ -74,11 +74,11 @@ class IssuableFinder
end end
def projects def projects
return if project?
return @projects if defined?(@projects) return @projects if defined?(@projects)
if current_user && params[:authorized_only].presence && !current_user_related? if project?
project
elsif current_user && params[:authorized_only].presence && !current_user_related?
current_user.authorized_projects current_user.authorized_projects
else else
ProjectsFinder.new.execute(current_user) ProjectsFinder.new.execute(current_user)
...@@ -102,14 +102,7 @@ class IssuableFinder ...@@ -102,14 +102,7 @@ class IssuableFinder
@milestones = @milestones =
if milestones? if milestones?
scope = scope = Milestone.where(project_id: projects)
if project
project.milestones
elsif projects
Milestone.where(project_id: projects)
else
Milestone.none
end
scope.where(title: params[:milestone_title]) scope.where(title: params[:milestone_title])
else else
...@@ -117,6 +110,14 @@ class IssuableFinder ...@@ -117,6 +110,14 @@ class IssuableFinder
end end
end end
def labels?
params[:label_name].present?
end
def no_labels?
labels? && params[:label_name] == Label::None.title
end
def assignee? def assignee?
params[:assignee_id].present? params[:assignee_id].present?
end end
...@@ -189,9 +190,7 @@ class IssuableFinder ...@@ -189,9 +190,7 @@ class IssuableFinder
def by_project(items) def by_project(items)
items = items =
if project if projects
items.of_projects(project)
elsif projects
items.of_projects(projects).references(:project) items.of_projects(projects).references(:project)
else else
items.none items.none
...@@ -210,18 +209,6 @@ class IssuableFinder ...@@ -210,18 +209,6 @@ class IssuableFinder
items.sort(params[:sort]) items.sort(params[:sort])
end end
def by_milestone(items)
if milestones?
if no_milestones?
items = items.where(milestone_id: [-1, nil])
else
items = items.where(milestone_id: milestones.try(:pluck, :id))
end
end
items
end
def by_assignee(items) def by_assignee(items)
if assignee? if assignee?
items = items.where(assignee_id: assignee.try(:id)) items = items.where(assignee_id: assignee.try(:id))
...@@ -238,9 +225,25 @@ class IssuableFinder ...@@ -238,9 +225,25 @@ class IssuableFinder
items items
end end
def by_milestone(items)
if milestones?
if no_milestones?
items = items.where(milestone_id: [-1, nil])
else
items = items.joins(:milestone).where(milestones: { title: params[:milestone_title] })
if projects
items = items.where(milestones: { project_id: projects })
end
end
end
items
end
def by_label(items) def by_label(items)
if params[:label_name].present? if labels?
if params[:label_name] == Label::None.title if no_labels?
items = items. items = items.
joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{klass.name}' AND label_links.target_id = #{klass.table_name}.id"). joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{klass.name}' AND label_links.target_id = #{klass.table_name}.id").
where(label_links: { id: nil }) where(label_links: { id: nil })
...@@ -249,8 +252,8 @@ class IssuableFinder ...@@ -249,8 +252,8 @@ class IssuableFinder
items = items.joins(:labels).where(labels: { title: label_names }) items = items.joins(:labels).where(labels: { title: label_names })
if project if projects
items = items.where('labels.project_id = :id', id: project.id) items = items.where(labels: { project_id: projects })
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment