Commit 701f57aa authored by Eugenia Grieff's avatar Eugenia Grieff

Add specs for N+1 queries for issue labels

parent ea372fa8
......@@ -18,7 +18,7 @@ module Issues
private
def associations_to_preload
%i(author assignees timelogs milestone)
%i(author assignees timelogs milestone project)
end
def header_to_value_hash
......
......@@ -4,11 +4,11 @@ require 'spec_helper'
RSpec.describe Issues::ExportCsvService do
let_it_be(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, :public, group: group) }
let!(:issue) { create(:issue, project: project, author: user) }
let!(:bad_issue) { create(:issue, project: project, author: user) }
let(:subject) { described_class.new(Issue.all, project) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :public, group: group) }
let_it_be(:issue) { create(:issue, project: project, author: user) }
let_it_be(:bad_issue) { create(:issue, project: project, author: user) }
subject { described_class.new(Issue.all, project) }
it 'renders csv to string' do
expect(subject.csv_data).to be_a String
......@@ -33,11 +33,11 @@ RSpec.describe Issues::ExportCsvService do
end
context 'includes' do
let(:milestone) { create(:milestone, title: 'v1.0', project: project) }
let(:idea_label) { create(:label, project: project, title: 'Idea') }
let(:feature_label) { create(:label, project: project, title: 'Feature') }
let_it_be(:milestone) { create(:milestone, title: 'v1.0', project: project) }
let_it_be(:idea_label) { create(:label, project: project, title: 'Idea') }
let_it_be(:feature_label) { create(:label, project: project, title: 'Feature') }
before do
before_all do
# Creating a timelog touches the updated_at timestamp of issue,
# so create these first.
issue.timelogs.create!(time_spent: 360, user: user)
......@@ -150,7 +150,7 @@ RSpec.describe Issues::ExportCsvService do
end
context 'with issues filtered by labels and project' do
let(:subject) do
subject do
described_class.new(
IssuesFinder.new(user,
project_id: project.id,
......@@ -162,6 +162,15 @@ RSpec.describe Issues::ExportCsvService do
expect(csv[0]['Issue ID']).to eq issue.iid.to_s
end
end
context 'performance' do
it 'does not run a query for each label link' do
control_count = ActiveRecord::QueryRecorder.new { csv }.count
create_list(:labeled_issue, 2, project: project, author: user, labels: [feature_label, idea_label])
expect { csv }.not_to exceed_query_limit(control_count)
end
end
end
context 'with minimal details' do
......
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