Skip to content
代码片段 群组 项目
未验证 提交 30e7d297 编辑于 作者: Max Fan's avatar Max Fan 提交者: GitLab
浏览文件

Merge branch 'optionally-skip-status-preloads-in-pipeline-serializer' into 'master'

Optionally skip status preloads for pipeline lists

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142947



Merged-by: default avatarMax Fan <mfan@gitlab.com>
Approved-by: default avatarJaviera Tapia <jtapia@gitlab.com>
Approved-by: default avatarMax Fan <mfan@gitlab.com>
Reviewed-by: default avatarMax Fan <mfan@gitlab.com>
Co-authored-by: default avatarHordur Freyr Yngvason <hfyngvason@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -149,15 +149,27 @@ def pipelines
Gitlab::PollingInterval.set_header(response, interval: 10_000)
serializer_options = {
disable_coverage: true,
disable_failed_builds: true,
preload: true
}
if Feature.enabled?(:skip_status_preload_in_pipeline_lists, @project, type: :gitlab_com_derisk)
serializer_options.merge!(
disable_manual_and_scheduled_actions: true,
preload_statuses: false,
preload_downstream_statuses: false
)
end
render json: {
pipelines: PipelineSerializer
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(
@pipelines,
preload: true,
disable_failed_builds: true,
disable_coverage: true
**serializer_options
),
count: {
all: @pipelines.count
......
......@@ -226,14 +226,26 @@ def downloadable_artifacts
private
def serialize_pipelines
serializer_options = {
disable_coverage: true,
disable_manual_and_scheduled_actions: true,
preload: true
}
if Feature.enabled?(:skip_status_preload_in_pipeline_lists, @project, type: :gitlab_com_derisk)
serializer_options.merge!(
disable_failed_builds: true,
preload_statuses: false,
preload_downstream_statuses: false
)
end
PipelineSerializer
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(
@pipelines,
disable_coverage: true,
preload: true,
disable_manual_and_scheduled_actions: true
**serializer_options
)
end
......
......@@ -6,17 +6,9 @@ class PipelineSerializer < BaseSerializer
# rubocop: disable CodeReuse/ActiveRecord
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.preload(preloaded_relations)
end
if paginated?
resource = paginator.paginate(resource)
end
if opts.delete(:preload)
resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
end
resource = resource.preload(preloaded_relations(**opts)) if resource.is_a?(ActiveRecord::Relation)
resource = paginator.paginate(resource) if paginated?
resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource) if opts.delete(:preload)
super(resource, opts)
end
......@@ -38,15 +30,15 @@ def represent_stages(resource)
private
def preloaded_relations
def preloaded_relations(preload_statuses: true, preload_downstream_statuses: true, **)
[
:pipeline_metadata,
:cancelable_statuses,
:retryable_builds,
:stages,
:latest_statuses,
:trigger_requests,
:user,
(:latest_statuses if preload_statuses),
{
manual_actions: :metadata,
scheduled_actions: :metadata,
......@@ -59,15 +51,15 @@ def preloaded_relations
project: [:route, { namespace: :route }],
triggered_by_pipeline: [{ project: [:route, { namespace: :route }] }, :user],
triggered_pipelines: [
(:latest_statuses if preload_downstream_statuses),
{
project: [:route, { namespace: :route }]
},
:source_job,
:latest_statuses,
:user
]
].compact
}
]
].compact
end
end
......
---
name: skip_status_preload_in_pipeline_lists
feature_issue_url:
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142947
rollout_issue_url: https://gitlab.com/gitlab-com/gl-infra/production/-/issues/17482
milestone: '16.9'
group: group::pipeline execution
type: gitlab_com_derisk
default_enabled: false
......@@ -6,7 +6,7 @@ module PipelineSerializer
private
def preloaded_relations
def preloaded_relations(...)
relations = super
project_relation = relations.detect { |item| item.is_a?(Hash) }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册