Commit 6d577b6c authored by Stan Hu's avatar Stan Hu

Merge branch 'ee-11178-fix-n1-queries-in-epics-controller-index' into 'master'

Preload labels in EpicsController#index

See merge request gitlab-org/gitlab-ee!13904
parents 64445350 2fb0ebf3
......@@ -99,7 +99,7 @@ class Groups::EpicsController < Groups::ApplicationController
end
def preload_for_collection
@preload_for_collection ||= [:group, :author]
@preload_for_collection ||= [:group, :author, :labels]
end
def authorize_create_epic!
......
---
title: Performance improvement when loading epics list
merge_request: 13904
author:
type: performance
......@@ -116,6 +116,26 @@ describe Groups::EpicsController do
end
end
context "when epic has multiple labels" do
render_views
let(:label) { create(:label) }
let!(:labeled_epic) { create(:labeled_epic, group: group, labels: [label]) }
it 'does not cause N+1 queries' do
get :index, params: { group_id: group }
control_count = ActiveRecord::QueryRecorder.new do
get :index, params: { group_id: group }
end
label = create(:label)
create(:labeled_epic, group: group, labels: [label])
expect { get :index, params: { group_id: group } }.not_to exceed_query_limit(control_count)
end
end
context 'when format is JSON' do
before do
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
......
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