diff options
author | Stan Hu <stanhu@gmail.com> | 2018-03-18 15:13:17 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-03-19 08:32:57 -0700 |
commit | 48f0eff37ab74ba4409dd28c5003898e2272a010 (patch) | |
tree | d83ad0b39ed3e0a5e1c04cd7bb5d59e415bb5081 | |
parent | ea5221aeb358ef6c349cfa09b9c6993bd7bd027d (diff) | |
download | gitlab-ce-48f0eff37ab74ba4409dd28c5003898e2272a010.tar.gz |
Remove N+1 queries in /admin/projects page
-rw-r--r-- | app/finders/admin/projects_finder.rb | 1 | ||||
-rw-r--r-- | spec/controllers/admin/projects_controller_spec.rb | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/app/finders/admin/projects_finder.rb b/app/finders/admin/projects_finder.rb index 5c507fe8d50..2c8f21c2400 100644 --- a/app/finders/admin/projects_finder.rb +++ b/app/finders/admin/projects_finder.rb @@ -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 diff --git a/spec/controllers/admin/projects_controller_spec.rb b/spec/controllers/admin/projects_controller_spec.rb index d5a3c250f31..cc200b9fed9 100644 --- a/spec/controllers/admin/projects_controller_spec.rb +++ b/spec/controllers/admin/projects_controller_spec.rb @@ -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 |