Commit e828e835 authored by Shinya Maeda's avatar Shinya Maeda

avoids N + 1 queries

parent 94f7595b
......@@ -17,7 +17,7 @@ module API
get ':id/pipeline_schedules' do
authorize! :read_pipeline_schedule, user_project
pipeline_schedules = user_project.pipeline_schedules
pipeline_schedules = user_project.pipeline_schedules.preload(:pipelines)
present paginate(pipeline_schedules), with: Entities::PipelineSchedule
end
......
......@@ -25,6 +25,18 @@ describe API::PipelineSchedules do
expect(response).to include_pagination_headers
expect(response).to match_response_schema('pipeline_schedules')
end
it 'avoids N + 1 queries' do
control_count = ActiveRecord::QueryRecorder.new do
get api("/projects/#{project.id}/pipeline_schedules", developer)
end.count
create_list(:ci_pipeline_schedule, 10, project: project, owner: developer)
expect do
get api("/projects/#{project.id}/pipeline_schedules", developer)
end.not_to exceed_query_limit(control_count)
end
end
context 'authenticated user with invalid permissions' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment