diff options
Diffstat (limited to 'spec/controllers/explore/projects_controller_spec.rb')
-rw-r--r-- | spec/controllers/explore/projects_controller_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/controllers/explore/projects_controller_spec.rb b/spec/controllers/explore/projects_controller_spec.rb index fd86501ff5d..4ec890a528f 100644 --- a/spec/controllers/explore/projects_controller_spec.rb +++ b/spec/controllers/explore/projects_controller_spec.rb @@ -138,6 +138,33 @@ RSpec.describe Explore::ProjectsController do end end + shared_examples 'avoids N+1 queries' do + [:index, :trending, :starred].each do |endpoint| + describe "GET #{endpoint}" do + render_views + + # some N+1 queries still exist + it 'avoids N+1 queries' do + projects = create_list(:project, 3, :repository, :public) + projects.each do |project| + pipeline = create(:ci_pipeline, :success, project: project, sha: project.commit.id) + create(:commit_status, :success, pipeline: pipeline, ref: pipeline.ref) + end + + control = ActiveRecord::QueryRecorder.new { get endpoint } + + new_projects = create_list(:project, 2, :repository, :public) + new_projects.each do |project| + pipeline = create(:ci_pipeline, :success, project: project, sha: project.commit.id) + create(:commit_status, :success, pipeline: pipeline, ref: pipeline.ref) + end + + expect { get endpoint }.not_to exceed_query_limit(control).with_threshold(8) + end + end + end + end + context 'when user is signed in' do let(:user) { create(:user) } @@ -147,6 +174,7 @@ RSpec.describe Explore::ProjectsController do include_examples 'explore projects' include_examples "blocks high page numbers" + include_examples 'avoids N+1 queries' context 'user preference sorting' do let(:project) { create(:project) } @@ -160,6 +188,7 @@ RSpec.describe Explore::ProjectsController do context 'when user is not signed in' do include_examples 'explore projects' include_examples "blocks high page numbers" + include_examples 'avoids N+1 queries' context 'user preference sorting' do let(:project) { create(:project) } |