Skip to content
Snippets Groups Projects
Unverified Commit 16a2eba5 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Count number of queries

parent 37e7fe2c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -19,6 +19,11 @@ class Projects::BuildsController < Projects::ApplicationController
else
@builds
end
@builds = @builds.includes([
{ pipeline: :project },
:project,
:tags
])
@builds = @builds.page(params[:page]).per(30)
end
 
Loading
Loading
Loading
Loading
@@ -68,7 +68,7 @@ module HasStatus
end
 
scope :created, -> { where(status: 'created') }
scope :relevant, -> { where.not(status: 'created') }
scope :relevant, -> { where(status: AVAILABLE_STATUSES - ['created']) }
scope :running, -> { where(status: 'running') }
scope :pending, -> { where(status: 'pending') }
scope :success, -> { where(status: 'success') }
Loading
Loading
---
title: Optimise builds endpoint
merge_request:
author:
Loading
Loading
@@ -10,6 +10,39 @@ describe Projects::BuildsController do
sign_in(user)
end
 
describe 'GET index' do
context 'number of queries' do
before do
Ci::Build::AVAILABLE_STATUSES.each do |status|
create_build(status, status)
end
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
def render
get :index, namespace_id: project.namespace,
project_id: project
end
it "verifies number of queries" do
recorded = ActiveRecord::QueryRecorder.new { render }
expect(recorded.count).to be_within(5).of(8)
end
def create_build(name, status)
pipeline = create(:ci_pipeline, project: project)
create(:ci_build, :tags, :triggered, :artifacts,
pipeline: pipeline, name: name, status: status)
end
end
end
describe 'GET status.json' do
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline) }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment