Skip to content

Prevent preloading unused relations in security report findings type

mo khan requested to merge 387238/n-plus-one into master

What does this MR do and why?

This change adds a test to ensure that an N+1 query is not present when loading merge requests in the pipelineSecurityReportFindingType and it removes preloading unused relations.

#387238 (closed)

Before:

       Expected a maximum of 16 queries, got 21:

       Query Diff:
       -----------
       SELECT "ci_pipelines".* FROM "ci_pipelines"...
       -- (expected: 0, got: 1)
          WHERE "ci_pipelines"."id" IN (575, 577, 578, 579, 576)

       SELECT "projects".* FROM "projects"...
       -- (expected: 0, got: 1)
          WHERE "projects"."id" = 1555

       SELECT "users".* FROM "users"...
       -- (expected: 0, got: 1)
          WHERE "users"."id" IN (2161, 2167, 2170, 2173, 2164)
       -- (expected: 0, got: 1)
          WHERE "users"."id" = 2150 LIMIT 1

       SELECT "merge_requests".* FROM "merge_requests"...
       -- (expected: 0, got: 1)
          WHERE "merge_requests"."id" IN (419, 421, 422, 423, 420)
     # ./ee/spec/graphql/types/pipeline_security_report_finding_type_spec.rb:359:in `block (4 levels) in <top (required)>'

After:

       Expected a maximum of 16 queries, got 18:

       Query Diff:
       -----------
       SELECT "merge_requests".* FROM "merge_requests"...
       -- (expected: 0, got: 1)
          WHERE "merge_requests"."id" IN (112, 110, 109, 108, 111)

       SELECT "users".* FROM "users"...
       -- (expected: 0, got: 1)
          WHERE "users"."id" IN (573, 577, 581, 585, 589)
     # ./ee/spec/graphql/types/pipeline_security_report_finding_type_spec.rb:365:in `block (4 levels) in <top (required)>'

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by mo khan

Merge request reports

Loading