Skip to content

Preload all associations in Vulnerability GraphQL API

What does this MR do?

Related to #233017

This change adds preloading associations in Vulnerability GraphQL to prevent N+1 queries. It also solves problem with N+1 query when loading Vulnerability Findings.

Queries

SELECT COUNT(*) AS count_all,
  "notes"."noteable_id" AS notes_noteable_id
FROM "notes"
WHERE "notes"."noteable_id" IN (20162469, 19936172, 19532875, 19483656, 19413496, 19315261, 18977208, 18897919, 18863350, 18860383, 18855948, 18792504, 18789638, 18466096, 18464659, 18374998, 18348449, 18347935, 18347890, 18347863, 18347848, 18347836, 18347835, 18347834, 18347833, 18347831, 18347830, 18347820, 18347819, 18347809, 18347808, 18347796, 18347780, 18347776, 18347716, 18347703, 18346158, 18342819, 18315938, 18163072, 18161573, 18147374, 18042963, 18021647, 17978213, 17930014, 17738687, 17530059, 17371314, 17370206, 17281958, 17172530, 17043690, 16842968, 16819248, 16819151, 16819140, 16819134, 16819131, 16819125, 16819118, 16816732, 16700143, 16613296, 16573099, 16311413, 16239404, 15769622, 15769471, 15704782, 15704133, 15685912, 15685887, 15683922, 15642544, 15572444, 15477483, 15161313, 14986497, 14921629, 14853550, 14378266, 13922331, 13672681, 13664986, 13348998, 13150952, 13017938, 12507547, 11915984, 11688089, 11625232, 11574953, 11520423, 11432834, 11317506, 11139665, 10861561, 10846951, 10846938)
  AND "notes"."noteable_type" = 'Vulnerability'
GROUP BY "notes"."noteable_id"

https://explain.depesz.com/s/qnuN (~1.4ms)

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
Edited by Alan (Maciej) Paruszewski

Merge request reports