From 20a07d26ff4be9c82271297e516df912109b05aa Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 18 May 2017 17:45:08 +0900 Subject: [PATCH] Include owner for pipeline_schedules. Improve N+1 spec. Use PipelineBasic for small payload. --- lib/api/entities.rb | 2 +- lib/api/pipeline_schedules.rb | 2 +- .../api/schemas/pipeline_schedule.json | 24 +------------------ spec/requests/api/pipeline_schedules_spec.rb | 6 ++++- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b2bc0a17142..f0260cf03f3 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -690,7 +690,7 @@ module API expose :id expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active expose :created_at, :updated_at, :deleted_at - expose :last_pipeline, using: Entities::Pipeline + expose :last_pipeline, using: Entities::PipelineBasic expose :owner, using: Entities::UserBasic end diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb index 27be796356c..c6c22f6e518 100644 --- a/lib/api/pipeline_schedules.rb +++ b/lib/api/pipeline_schedules.rb @@ -17,7 +17,7 @@ module API get ':id/pipeline_schedules' do 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 end diff --git a/spec/fixtures/api/schemas/pipeline_schedule.json b/spec/fixtures/api/schemas/pipeline_schedule.json index 46309b212a1..9d7853d0f78 100644 --- a/spec/fixtures/api/schemas/pipeline_schedule.json +++ b/spec/fixtures/api/schemas/pipeline_schedule.json @@ -17,29 +17,7 @@ "id": { "type": "integer" }, "sha": { "type": "string" }, "ref": { "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"] } + "status": { "type": "string" } }, "additionalProperties": false }, diff --git a/spec/requests/api/pipeline_schedules_spec.rb b/spec/requests/api/pipeline_schedules_spec.rb index 1b44043907b..74de2f0ba4a 100644 --- a/spec/requests/api/pipeline_schedules_spec.rb +++ b/spec/requests/api/pipeline_schedules_spec.rb @@ -30,8 +30,12 @@ describe API::PipelineSchedules do get api("/projects/#{project.id}/pipeline_schedules", developer) end.count - create_list(:ci_pipeline_schedule, 10, project: project, owner: developer) + create_list(:ci_pipeline_schedule, 10, project: project) .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) end