Eliminate N+1 queries in Dashboard::TodosController
This appears to bring down the number of SQL queries on GitLab.com for my Todos page from 672 to 100. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/43042
This commit is contained in:
parent
7f6de7fe29
commit
211a00473b
4 changed files with 35 additions and 1 deletions
|
@ -10,6 +10,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
|
|||
def index
|
||||
@sort = params[:sort]
|
||||
@todos = @todos.page(params[:page])
|
||||
@todos = @todos.with_api_entity_associations
|
||||
|
||||
return if redirect_out_of_range(@todos)
|
||||
end
|
||||
|
|
|
@ -170,7 +170,7 @@ module TodosHelper
|
|||
end
|
||||
|
||||
def todo_group_options
|
||||
groups = current_user.authorized_groups.map do |group|
|
||||
groups = current_user.authorized_groups.with_route.map do |group|
|
||||
{ id: group.id, text: group.full_name }
|
||||
end
|
||||
|
||||
|
|
5
changelogs/unreleased/sh-optimize-todos-controller.yml
Normal file
5
changelogs/unreleased/sh-optimize-todos-controller.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Eliminate N+1 queries in Dashboard::TodosController
|
||||
merge_request: 29954
|
||||
author:
|
||||
type: performance
|
|
@ -44,6 +44,34 @@ describe Dashboard::TodosController do
|
|||
end
|
||||
end
|
||||
|
||||
context "with render_views" do
|
||||
render_views
|
||||
|
||||
it 'avoids N+1 queries', :request_store do
|
||||
merge_request = create(:merge_request, source_project: project)
|
||||
create(:todo, project: project, author: author, user: user, target: merge_request)
|
||||
create(:issue, project: project, assignees: [user])
|
||||
|
||||
group = create(:group)
|
||||
group.add_owner(user)
|
||||
|
||||
get :index
|
||||
|
||||
control = ActiveRecord::QueryRecorder.new { get :index }
|
||||
|
||||
create(:issue, project: project, assignees: [user])
|
||||
group_2 = create(:group)
|
||||
group_2.add_owner(user)
|
||||
project_2 = create(:project)
|
||||
project_2.add_developer(user)
|
||||
merge_request_2 = create(:merge_request, source_project: project_2)
|
||||
create(:todo, project: project, author: author, user: user, target: merge_request_2)
|
||||
|
||||
expect { get :index }.not_to exceed_query_limit(control)
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'group authorization' do
|
||||
it 'renders 404 when user does not have read access on given group' do
|
||||
unauthorized_group = create(:group, :private)
|
||||
|
|
Loading…
Reference in a new issue