Commit dab3ae39 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not paginate pipelines active relation twice

parent 8cca6c83
......@@ -15,7 +15,6 @@ class Projects::PipelinesController < Projects::ApplicationController
@pipelines = PipelinesFinder
.new(project, scope: @scope)
.execute
.preload(:stages)
.page(params[:page])
.per(30)
......@@ -24,8 +23,6 @@ class Projects::PipelinesController < Projects::ApplicationController
@finished_count = limited_pipelines_count(project, 'finished')
@pipelines_count = limited_pipelines_count(project)
Gitlab::Ci::Pipeline::Preloader.preload!(@pipelines)
respond_to do |format|
format.html
format.json do
......@@ -35,7 +32,7 @@ class Projects::PipelinesController < Projects::ApplicationController
pipelines: PipelineSerializer
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(@pipelines, disable_coverage: true),
.represent(@pipelines, disable_coverage: true, preload: true),
count: {
all: @pipelines_count,
running: @running_count,
......
class PipelineSerializer < BaseSerializer
include WithPagination
InvalidResourceError = Class.new(StandardError)
entity PipelineDetailsEntity
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.preload([
:stages,
:retryable_builds,
:cancelable_statuses,
:trigger_requests,
......@@ -19,11 +17,12 @@ class PipelineSerializer < BaseSerializer
])
end
if paginated?
super(@paginator.paginate(resource), opts)
else
super(resource, opts)
if opts.delete(:preload)
resource = @paginator.paginate(resource) if paginated?
resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
end
super(resource, opts)
end
def represent_status(resource)
......
......@@ -36,7 +36,7 @@ describe Projects::PipelinesController do
expect(json_response['count']['running']).to eq '1'
expect(json_response['count']['pending']).to eq '1'
expect(json_response['count']['finished']).to eq '2'
expect(queries.count).to be < 32
expect(queries.count).to be_within(2).of(29)
end
it 'does not include coverage data for the pipelines' do
......
......@@ -18,5 +18,15 @@ describe Gitlab::Ci::Pipeline::Preloader do
described_class.preload!([pipeline])
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
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