summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/finders/labels_finder.rb13
-rw-r--r--changelogs/unreleased/labels-finder-optimize-project.yml4
2 files changed, 15 insertions, 2 deletions
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb
index fa0e2a5e3d8..e52083f86e4 100644
--- a/app/finders/labels_finder.rb
+++ b/app/finders/labels_finder.rb
@@ -20,8 +20,17 @@ class LabelsFinder < UnionFinder
if project?
if project
- label_ids << project.group.labels if project.group.present?
- label_ids << project.labels
+ 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
+ end
end
else
label_ids << Label.where(group_id: projects.group_ids)
diff --git a/changelogs/unreleased/labels-finder-optimize-project.yml b/changelogs/unreleased/labels-finder-optimize-project.yml
new file mode 100644
index 00000000000..0d2e82e1efe
--- /dev/null
+++ b/changelogs/unreleased/labels-finder-optimize-project.yml
@@ -0,0 +1,4 @@
+---
+title: Optimize labels finder query when searching for a project with a group
+merge_request:
+author: mhasbini