summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-23 13:29:21 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-23 13:29:21 +0200
commitdab3ae39a2093fa924daf9c1902a2784002cca63 (patch)
tree9c183546ec1862740f589ecd47e29edf335db8f6 /app
parent8cca6c83a99100fcf3a0a3a56f10eebe3c9b7716 (diff)
downloadgitlab-ce-dab3ae39a2093fa924daf9c1902a2784002cca63.tar.gz
Do not paginate pipelines active relation twice
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/pipelines_controller.rb5
-rw-r--r--app/serializers/pipeline_serializer.rb13
2 files changed, 7 insertions, 11 deletions
diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb
index 2b758b960c2..768595ceeb4 100644
--- a/app/controllers/projects/pipelines_controller.rb
+++ b/app/controllers/projects/pipelines_controller.rb
@@ -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,
diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb
index 7181f8a6b04..68325cbffa8 100644
--- a/app/serializers/pipeline_serializer.rb
+++ b/app/serializers/pipeline_serializer.rb
@@ -1,14 +1,12 @@
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)