Commit a956fac2 authored by Felipe Artur's avatar Felipe Artur

Remove unnecessary query from labels filter

parent 5c51cbca
......@@ -71,7 +71,7 @@ class LabelsFinder < UnionFinder
end
def projects?
params[:project_ids].present?
params[:project_ids]
end
def only_group_labels?
......
......@@ -304,6 +304,12 @@ module IssuablesHelper
issuable.model_name.human.downcase
end
def selected_labels
Array(params[:label_name]).map do |label_name|
Label.new(title: label_name)
end
end
private
def sidebar_gutter_collapsed?
......
......@@ -22,7 +22,7 @@
= render "shared/issuable/milestone_dropdown", selected: finder.milestones.try(:first), name: :milestone_title, show_any: true, show_upcoming: true, show_started: true
.filter-item.inline.labels-filter
= render "shared/issuable/label_dropdown", selected: finder.labels.select(:title).uniq, use_id: false, selected_toggle: params[:label_name], data_options: { field_name: "label_name[]" }
= render "shared/issuable/label_dropdown", selected: selected_labels, use_id: false, selected_toggle: params[:label_name], data_options: { field_name: "label_name[]" }
- if issuable_filter_present?
.filter-item.inline.reset-filters
......
---
title: Remove unecessary query from labels filter
merge_request:
author:
type: performance
......@@ -192,4 +192,33 @@ describe IssuablesHelper do
expect(JSON.parse(helper.issuable_initial_data(issue))).to eq(expected_data)
end
end
describe '#selected_labels' do
context 'if label_name param is a string' do
it 'returns a new label with title' do
allow(helper).to receive(:params)
.and_return(ActionController::Parameters.new(label_name: 'test label'))
labels = helper.selected_labels
expect(labels).to be_an(Array)
expect(labels.size).to eq(1)
expect(labels.first.title).to eq('test label')
end
end
context 'if label_name param is an array' do
it 'returns a new label with title for each element' do
allow(helper).to receive(:params)
.and_return(ActionController::Parameters.new(label_name: ['test label 1', 'test label 2']))
labels = helper.selected_labels
expect(labels).to be_an(Array)
expect(labels.size).to eq(2)
expect(labels.first.title).to eq('test label 1')
expect(labels.second.title).to eq('test label 2')
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