Optimise includes
This commit is contained in:
parent
8a1c12aa6f
commit
b828a98c1c
2 changed files with 11 additions and 2 deletions
|
@ -13,7 +13,15 @@ class PipelineSerializer < BaseSerializer
|
|||
|
||||
def represent(resource, opts = {})
|
||||
if resource.is_a?(ActiveRecord::Relation)
|
||||
resource = resource.includes(project: :namespace)
|
||||
resource = resource.includes(:project)
|
||||
resource = resource.includes(:pending_builds,
|
||||
:retryable_builds,
|
||||
:cancelable_statuses,
|
||||
:manual_actions,
|
||||
:artifacts)
|
||||
resource = resource.includes(pending_builds: :project)
|
||||
resource = resource.includes(manual_actions: :project)
|
||||
resource = resource.includes(artifacts: :project)
|
||||
end
|
||||
|
||||
if paginated?
|
||||
|
|
|
@ -105,7 +105,8 @@ describe PipelineSerializer do
|
|||
|
||||
it "verifies number of queries" do
|
||||
recorded = ActiveRecord::QueryRecorder.new { subject }
|
||||
expect(recorded.count).to be_within(200).of(10)
|
||||
expect(recorded.count).to be_within(10).of(230)
|
||||
expect(recorded.cached_count).to be_within(5).of(5)
|
||||
end
|
||||
|
||||
def create_pipeline(status)
|
||||
|
|
Loading…
Reference in a new issue