Skip to content

Remove N+1 query from Issue::Metrics#record!

Adam Cohen requested to merge 4794-add-eager-loading-to-issue-metrics into master

What does this MR do?

This MR preloads the lists relation on labels to remove an N+1 query

What are the relevant issue numbers?

#4794 (closed)

Database

Before

SELECT "lists".* FROM "lists" WHERE "lists"."label_id" = 2
SELECT "lists".* FROM "lists" WHERE "lists"."label_id" = 3
SELECT "lists".* FROM "lists" WHERE "lists"."label_id" = 4
SELECT "lists".* FROM "lists" WHERE "lists"."label_id" = 5

After

SELECT "labels".* FROM "labels" INNER JOIN "label_links" ON "labels"."id" = "label_links"."label_id" WHERE "label_links"."target_id" = 1 AND "label_links"."target_type" = 'Issue' ORDER BY "labels"."title" ASC

SELECT "lists".* FROM "lists" WHERE "lists"."label_id" IN (2, 3, 4, 5)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #4794 (closed)

Edited by Adam Cohen

Merge request reports