Include owner for pipeline_schedules. Improve N+1 spec. Use PipelineBasic for small payload.
This commit is contained in:
parent
17b9128b30
commit
20a07d26ff
4 changed files with 8 additions and 26 deletions
|
@ -690,7 +690,7 @@ module API
|
||||||
expose :id
|
expose :id
|
||||||
expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
|
expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
|
||||||
expose :created_at, :updated_at, :deleted_at
|
expose :created_at, :updated_at, :deleted_at
|
||||||
expose :last_pipeline, using: Entities::Pipeline
|
expose :last_pipeline, using: Entities::PipelineBasic
|
||||||
expose :owner, using: Entities::UserBasic
|
expose :owner, using: Entities::UserBasic
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ module API
|
||||||
get ':id/pipeline_schedules' do
|
get ':id/pipeline_schedules' do
|
||||||
authorize! :read_pipeline_schedule, user_project
|
authorize! :read_pipeline_schedule, user_project
|
||||||
|
|
||||||
pipeline_schedules = user_project.pipeline_schedules.includes(last_pipeline: {statuses: :latest})
|
pipeline_schedules = user_project.pipeline_schedules.includes([:owner, last_pipeline: {statuses: :latest}])
|
||||||
|
|
||||||
present paginate(pipeline_schedules), with: Entities::PipelineSchedule
|
present paginate(pipeline_schedules), with: Entities::PipelineSchedule
|
||||||
end
|
end
|
||||||
|
|
24
spec/fixtures/api/schemas/pipeline_schedule.json
vendored
24
spec/fixtures/api/schemas/pipeline_schedule.json
vendored
|
@ -17,29 +17,7 @@
|
||||||
"id": { "type": "integer" },
|
"id": { "type": "integer" },
|
||||||
"sha": { "type": "string" },
|
"sha": { "type": "string" },
|
||||||
"ref": { "type": "string" },
|
"ref": { "type": "string" },
|
||||||
"status": { "type": "string" },
|
"status": { "type": "string" }
|
||||||
"before_sha": { "type": ["string", "null"] },
|
|
||||||
"tag": { "type": ["boolean", "null"] },
|
|
||||||
"yaml_errors": { "type": ["string", "null"] },
|
|
||||||
"user": {
|
|
||||||
"type": ["object", "null"],
|
|
||||||
"properties": {
|
|
||||||
"name": { "type": "string" },
|
|
||||||
"username": { "type": "string" },
|
|
||||||
"id": { "type": "integer" },
|
|
||||||
"state": { "type": "string" },
|
|
||||||
"avatar_url": { "type": "uri" },
|
|
||||||
"web_url": { "type": "uri" }
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
},
|
|
||||||
"created_at": { "type": "date" },
|
|
||||||
"updated_at": { "type": "date" },
|
|
||||||
"started_at": { "type": "date" },
|
|
||||||
"finished_at": { "type": "date" },
|
|
||||||
"committed_at": { "type": ["string", "null"] },
|
|
||||||
"duration": { "type": ["integer", "null"] },
|
|
||||||
"coverage": { "type": ["string", "null"] }
|
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,8 +30,12 @@ describe API::PipelineSchedules do
|
||||||
get api("/projects/#{project.id}/pipeline_schedules", developer)
|
get api("/projects/#{project.id}/pipeline_schedules", developer)
|
||||||
end.count
|
end.count
|
||||||
|
|
||||||
create_list(:ci_pipeline_schedule, 10, project: project, owner: developer)
|
create_list(:ci_pipeline_schedule, 10, project: project)
|
||||||
.each do |pipeline_schedule|
|
.each do |pipeline_schedule|
|
||||||
|
create(:user).tap do |user|
|
||||||
|
project.add_developer(user)
|
||||||
|
pipeline_schedule.update_attributes(owner: user)
|
||||||
|
end
|
||||||
pipeline_schedule.pipelines << build(:ci_pipeline, project: project)
|
pipeline_schedule.pipelines << build(:ci_pipeline, project: project)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue