diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-24 17:55:24 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-24 17:55:24 +0300 |
commit | f0d7445b88f6598db85198296c076bf59508188a (patch) | |
tree | 6da862151641d3eb90ad2256f5db45e68f8ace7d /app/serializers/pipeline_serializer.rb | |
parent | bc9a0e10b50430e0b253a15d1628b6776d0bd9fe (diff) |
Reduce pipeline serialization queries when preloaded
Diffstat (limited to 'app/serializers/pipeline_serializer.rb')
-rw-r--r-- | app/serializers/pipeline_serializer.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index 68325cbffa8..d4b85f5aeb4 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -3,8 +3,11 @@ class PipelineSerializer < BaseSerializer entity PipelineDetailsEntity def represent(resource, opts = {}) - if resource.is_a?(ActiveRecord::Relation) + if paginated? && !resource.respond_to?(:page) + raise Gitlab::Serializer::Pagination::InvalidResourceError + end + if resource.is_a?(ActiveRecord::Relation) resource = resource.preload([ :stages, :retryable_builds, @@ -18,7 +21,6 @@ class PipelineSerializer < BaseSerializer end if opts.delete(:preload) - resource = @paginator.paginate(resource) if paginated? resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource) end @@ -35,7 +37,7 @@ class PipelineSerializer < BaseSerializer def represent_stages(resource) return {} unless resource.present? - data = represent(resource, { only: [{ details: [:stages] }] }) + data = represent(resource, { only: [{ details: [:stages] }], preload: true }) data.dig(:details, :stages) || [] end end |