diff options
author | Stan Hu <stanhu@gmail.com> | 2017-11-19 06:35:25 -0800 |
---|---|---|
committer | Francisco Lopez <fjlopez@gitlab.com> | 2017-12-01 18:32:12 +0100 |
commit | 88e3ce30ae97ac8eb4b25381cfbe7772819cce0c (patch) | |
tree | a8e68aa062b64e726fd493f68973c8a8b0f7ba33 /spec | |
parent | c594659fea15c6dd17b9ea4c6b88c5a418f10ab9 (diff) | |
download | gitlab-ce-88e3ce30ae97ac8eb4b25381cfbe7772819cce0c.tar.gz |
Optimize API /groups/:id/projects by preloading associations
Closes #40308
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/groups_spec.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index 04a658cd6c3..554723d6b1e 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -401,6 +401,20 @@ describe API::Groups do expect(response).to have_gitlab_http_status(404) end + + it 'avoids N+1 queries' do + get api("/groups/#{group1.id}/projects", admin) + + control_count = ActiveRecord::QueryRecorder.new do + get api("/groups/#{group1.id}/projects", admin) + end.count + + create(:project, namespace: group1) + + expect do + get api("/groups/#{group1.id}/projects", admin) + end.not_to exceed_query_limit(control_count) + end end context 'when using group path in URL' do |