Commit 6e6da4bb authored by mhasbini's avatar mhasbini

Optimize labels finder query

Optimize labels finder query when searching for a project with a group
parent 37b5b7a5
...@@ -20,9 +20,18 @@ class LabelsFinder < UnionFinder ...@@ -20,9 +20,18 @@ class LabelsFinder < UnionFinder
if project? if project?
if project if project
label_ids << project.group.labels if project.group.present? if project.group.present?
labels_table = Label.arel_table
label_ids << Label.where(
labels_table[:type].eq('GroupLabel').and(labels_table[:group_id].eq(project.group.id)).or(
labels_table[:type].eq('ProjectLabel').and(labels_table[:project_id].eq(project.id))
)
)
else
label_ids << project.labels label_ids << project.labels
end end
end
else else
label_ids << Label.where(group_id: projects.group_ids) label_ids << Label.where(group_id: projects.group_ids)
label_ids << Label.where(project_id: projects.select(:id)) label_ids << Label.where(project_id: projects.select(:id))
......
---
title: Optimize labels finder query when searching for a project with a group
merge_request:
author: mhasbini
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