Commit 93f9e71b authored by Kamil Trzcinski's avatar Kamil Trzcinski

Further optimise queries

parent 62919a17
...@@ -13,16 +13,18 @@ class PipelineSerializer < BaseSerializer ...@@ -13,16 +13,18 @@ class PipelineSerializer < BaseSerializer
def represent(resource, opts = {}) def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation) if resource.is_a?(ActiveRecord::Relation)
resource = resource.includes(:pending_builds, project_includes = [ { namespace: :route }, :route ]
resource = resource.includes(
:retryable_builds, :retryable_builds,
:cancelable_statuses, :cancelable_statuses,
:manual_actions, :trigger_requests
:artifacts, )
:trigger_requests) resource = resource.includes(
resource = resource.includes(pending_builds: :project) project: project_includes,
resource = resource.includes(project: :namespace) pending_builds: [:project],
resource = resource.includes(manual_actions: { project: :namespace }) manual_actions: { project: project_includes },
resource = resource.includes(artifacts: { project: :namespace }) artifacts: { project: project_includes }
)
end end
if paginated? if paginated?
......
...@@ -112,7 +112,7 @@ describe PipelineSerializer do ...@@ -112,7 +112,7 @@ describe PipelineSerializer do
it "verifies number of queries" do it "verifies number of queries" do
recorded = ActiveRecord::QueryRecorder.new { subject } 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) expect(recorded.cached_count).to be_within(5).of(5)
end end
......
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