Extract preloaded_relations into method
This commit is contained in:
parent
7b0f9f82f6
commit
726f142dd2
1 changed files with 23 additions and 17 deletions
|
@ -7,23 +7,7 @@ class PipelineSerializer < BaseSerializer
|
|||
# rubocop: disable CodeReuse/ActiveRecord
|
||||
def represent(resource, opts = {})
|
||||
if resource.is_a?(ActiveRecord::Relation)
|
||||
resource = resource.preload([
|
||||
:stages,
|
||||
:retryable_builds,
|
||||
:cancelable_statuses,
|
||||
:trigger_requests,
|
||||
:manual_actions,
|
||||
:scheduled_actions,
|
||||
:artifacts,
|
||||
:merge_request,
|
||||
{
|
||||
pending_builds: :project,
|
||||
project: [:route, { namespace: :route }],
|
||||
artifacts: {
|
||||
project: [:route, { namespace: :route }]
|
||||
}
|
||||
}
|
||||
])
|
||||
resource = resource.preload(preloaded_relations)
|
||||
end
|
||||
|
||||
if paginated?
|
||||
|
@ -51,4 +35,26 @@ class PipelineSerializer < BaseSerializer
|
|||
data = represent(resource, { only: [{ details: [:stages] }], preload: true })
|
||||
data.dig(:details, :stages) || []
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def preloaded_relations
|
||||
[
|
||||
:stages,
|
||||
:retryable_builds,
|
||||
:cancelable_statuses,
|
||||
:trigger_requests,
|
||||
:manual_actions,
|
||||
:scheduled_actions,
|
||||
:artifacts,
|
||||
:merge_request,
|
||||
{
|
||||
pending_builds: :project,
|
||||
project: [:route, { namespace: :route }],
|
||||
artifacts: {
|
||||
project: [:route, { namespace: :route }]
|
||||
}
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue