Further optimise queries

This commit is contained in:
Kamil Trzcinski 2017-04-06 15:21:25 +02:00
parent 62919a17e1
commit 93f9e71b0d
No known key found for this signature in database
GPG key ID: 4505F5C7E12C6A5A
2 changed files with 11 additions and 9 deletions

View file

@ -13,16 +13,18 @@ class PipelineSerializer < BaseSerializer
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.includes(:pending_builds,
project_includes = [ { namespace: :route }, :route ]
resource = resource.includes(
:retryable_builds,
:cancelable_statuses,
:manual_actions,
:artifacts,
:trigger_requests)
resource = resource.includes(pending_builds: :project)
resource = resource.includes(project: :namespace)
resource = resource.includes(manual_actions: { project: :namespace })
resource = resource.includes(artifacts: { project: :namespace })
:trigger_requests
)
resource = resource.includes(
project: project_includes,
pending_builds: [:project],
manual_actions: { project: project_includes },
artifacts: { project: project_includes }
)
end
if paginated?

View file

@ -112,7 +112,7 @@ describe PipelineSerializer do
it "verifies number of queries" do
recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(10).of(230)
expect(recorded.count).to be_within(10).of(93)
expect(recorded.cached_count).to be_within(5).of(5)
end