Skip to content

Reduce queries on Controller Groups::LabelsController#index [RUN AS-IF-FOSS] [RUN ALL RSPEC]

What does this MR do?

Related to #21034 (closed) Group::Labels controller

Screenshots (strongly suggested)

performance bar before

image

image

performance bar after

image

image

Database

Group Labels for GitLab.org: https://gitlab.com/groups/gitlab-org/-/labels

Explain plan: https://explain.depesz.com/s/YeOw

 Index Scan using index_subscriptions_on_subscribable_and_user_id_and_project_id on public.subscriptions  (cost=0.42..42.25 rows=1 width=41) (actual time=7.093..39.648 rows=3 loops=1)
   Index Cond: ((subscriptions.subscribable_id = ANY ('{3079031,3704995,11832434,11832683,11832684,14931416,16876290,14540790,10438591,11434168,15904538,1890178,16648665,16198756,11832677,11832671,3121561,18275109,10421239,18275109,18275109}'::integer[])) AND ((subscriptions.subscribable_type)::text = 'Label'::text) AND (subscriptions.user_id = 5708766) AND (subscriptions.project_id IS NULL))
   Buffers: shared hit=37 read=26
   I/O Timings: read=39.039

SQL before

individual SQL generated for each Label (2 times per label)

SELECT
    "subscriptions".*
FROM
    "subscriptions"
WHERE
    "subscriptions"."subscribable_id" = 11832681
    AND "subscriptions"."subscribable_type" = 'Label'
    AND "subscriptions"."user_id" = 5708766
    AND "subscriptions"."project_id" IS NULL
LIMIT 1

SQL after

SQL generated once for all labels

SELECT
    "subscriptions".*
FROM
    "subscriptions"
WHERE
    "subscriptions"."subscribable_id" IN (3079031, 3704995, 11832434, 11832683, 11832684, 14931416, 16876290, 14540790, 10438591, 11434168, 15904538, 1890178, 16648665, 16198756, 11832677, 11832671, 3121561, 18275109, 10421239, 18275109, 18275109)
    AND "subscriptions"."subscribable_type" IN ('Label')
    AND "subscriptions"."project_id" IS NULL
    AND "subscriptions"."user_id" = 5708766

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 Terri Chu

Merge request reports

Loading