Skip to content
Snippets Groups Projects
Commit dab3ae39 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Do not paginate pipelines active relation twice

parent 8cca6c83
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -15,7 +15,6 @@ class Projects::PipelinesController < Projects::ApplicationController
@pipelines = PipelinesFinder
.new(project, scope: @scope)
.execute
.preload(:stages)
.page(params[:page])
.per(30)
 
Loading
Loading
@@ -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
Loading
Loading
@@ -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,
Loading
Loading
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,
Loading
Loading
@@ -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)
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment