Remove N+1 queries in /admin/projects page

This commit is contained in:
Stan Hu 2018-03-18 15:13:17 -07:00
parent ea5221aeb3
commit 48f0eff37a
2 changed files with 11 additions and 0 deletions

View File

@ -16,6 +16,7 @@ class Admin::ProjectsFinder
items = by_archived(items)
items = by_personal(items)
items = by_name(items)
items = items.includes(namespace: [:owner])
sort(items).page(params[:page])
end

View File

@ -31,5 +31,15 @@ describe Admin::ProjectsController do
expect(response.body).not_to match(pending_delete_project.name)
expect(response.body).to match(project.name)
end
it 'does not have N+1 queries', :use_clean_rails_memory_store_caching, :request_store do
get :index
control_count = ActiveRecord::QueryRecorder.new { get :index }.count
create(:project)
expect { get :index }.not_to exceed_query_limit(control_count)
end
end
end