Commit 2e7965e9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not paginate pipelines active relation twice

parent 6e015c2b
...@@ -17,7 +17,6 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -17,7 +17,6 @@ class Projects::PipelinesController < Projects::ApplicationController
@pipelines = PipelinesFinder @pipelines = PipelinesFinder
.new(project, scope: @scope) .new(project, scope: @scope)
.execute .execute
.preload(:stages)
.page(params[:page]) .page(params[:page])
.per(30) .per(30)
...@@ -26,8 +25,6 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -26,8 +25,6 @@ class Projects::PipelinesController < Projects::ApplicationController
@finished_count = limited_pipelines_count(project, 'finished') @finished_count = limited_pipelines_count(project, 'finished')
@pipelines_count = limited_pipelines_count(project) @pipelines_count = limited_pipelines_count(project)
Gitlab::Ci::Pipeline::Preloader.preload!(@pipelines)
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
...@@ -37,7 +34,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -37,7 +34,7 @@ class Projects::PipelinesController < Projects::ApplicationController
pipelines: PipelineSerializer pipelines: PipelineSerializer
.new(project: @project, current_user: @current_user) .new(project: @project, current_user: @current_user)
.with_pagination(request, response) .with_pagination(request, response)
.represent(@pipelines, disable_coverage: true), .represent(@pipelines, disable_coverage: true, preload: true),
count: { count: {
all: @pipelines_count, all: @pipelines_count,
running: @running_count, running: @running_count,
......
class PipelineSerializer < BaseSerializer class PipelineSerializer < BaseSerializer
include WithPagination include WithPagination
InvalidResourceError = Class.new(StandardError)
entity PipelineDetailsEntity entity PipelineDetailsEntity
def represent(resource, opts = {}) def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation) if resource.is_a?(ActiveRecord::Relation)
resource = resource.preload([ resource = resource.preload([
:stages,
:retryable_builds, :retryable_builds,
:cancelable_statuses, :cancelable_statuses,
:trigger_requests, :trigger_requests,
...@@ -21,11 +19,12 @@ class PipelineSerializer < BaseSerializer ...@@ -21,11 +19,12 @@ class PipelineSerializer < BaseSerializer
]) ])
end end
if paginated? if opts.delete(:preload)
super(@paginator.paginate(resource), opts) resource = @paginator.paginate(resource) if paginated?
else resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
super(resource, opts)
end end
super(resource, opts)
end end
def represent_status(resource) def represent_status(resource)
......
...@@ -36,7 +36,7 @@ describe Projects::PipelinesController do ...@@ -36,7 +36,7 @@ describe Projects::PipelinesController do
expect(json_response['count']['running']).to eq '1' expect(json_response['count']['running']).to eq '1'
expect(json_response['count']['pending']).to eq '1' expect(json_response['count']['pending']).to eq '1'
expect(json_response['count']['finished']).to eq '2' expect(json_response['count']['finished']).to eq '2'
expect(queries.count).to be < 32 expect(queries.count).to be_within(2).of(29)
end end
it 'does not include coverage data for the pipelines' do it 'does not include coverage data for the pipelines' do
......
...@@ -18,5 +18,15 @@ describe Gitlab::Ci::Pipeline::Preloader do ...@@ -18,5 +18,15 @@ describe Gitlab::Ci::Pipeline::Preloader do
described_class.preload!([pipeline]) described_class.preload!([pipeline])
end end
it 'returns original collection' do
allow(commit).to receive(:lazy_author)
allow(pipeline).to receive(:number_of_warnings)
allow(stage).to receive(:number_of_warnings)
pipelines = [pipeline, pipeline]
expect(described_class.preload!(pipelines)).to eq pipelines
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment