Replace Group ancestors scope with linear version
What does this MR do and why?
In this MR, we're switching the behavior of the method Group#ids_with_disabled_email
to use the linear version. The new behavior is behind the linear_group_ancestor_scopes
feature flag.
Database changes
In these examples, we're passing 6k groups to the query to test it with heavy data.
The old query was:
SELECT "id"
FROM
(SELECT *
FROM namespaces) AS namespaces_with_emails_disabled
WHERE "namespaces_with_emails_disabled"."id" IN
(SELECT "namespaces"."id"
FROM "namespaces"
INNER JOIN "members" ON "namespaces"."id" = "members"."source_id"
WHERE "members"."type" = 'GroupMember'
AND "members"."source_type" = 'Namespace'
AND "namespaces"."type" = 'Group'
AND "members"."user_id" = 1614863
AND "members"."requested_at" IS NULL
AND (access_level >= 10))
AND (EXISTS
(WITH RECURSIVE "base_and_ancestors" AS (
(SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND (id = namespaces_with_emails_disabled.id))
UNION
(SELECT "namespaces".*
FROM "namespaces",
"base_and_ancestors"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" = "base_and_ancestors"."parent_id")) SELECT 1
FROM "base_and_ancestors" AS "namespaces"
WHERE "namespaces"."emails_disabled" = TRUE
LIMIT 1))
This is the query plan and the execution times:
Time: 208.663 ms
- planning: 1.798 ms
- execution: 206.865 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 90505 (~707.10 MiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
The new query is:
SELECT "id"
FROM
(SELECT *
FROM namespaces) AS namespaces_with_emails_disabled
WHERE "namespaces_with_emails_disabled"."id" IN
(SELECT "namespaces"."id"
FROM "namespaces"
INNER JOIN "members" ON "namespaces"."id" = "members"."source_id"
WHERE "members"."type" = 'GroupMember'
AND "members"."source_type" = 'Namespace'
AND "namespaces"."type" = 'Group'
AND "members"."user_id" = 1614863
AND "members"."requested_at" IS NULL
AND (access_level >= 10))
AND (EXISTS
(SELECT 1
FROM
(SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."id" IN
(SELECT unnest(traversal_ids)
FROM "namespaces"
WHERE (id = namespaces_with_emails_disabled.id))) namespaces
WHERE "namespaces"."emails_disabled" = TRUE
LIMIT 1))
This is the query plan and the execution times:
Time: 117.777 ms
- planning: 1.419 ms
- execution: 116.358 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 115075 (~899.00 MiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
How to set up and validate locally
Example below:
-
Enable the feature flag for linear scopes
Feature.enable(:use_traversal_ids)
-
Enable the feature flag for linear ancestors scopes
Feature.enable(:use_traversal_ids_for_ancestor_scopes)
-
Enable the feature flag for
Ci::Runner
linear ancestors scopesFeature.enable(:linear_group_ancestor_scopes)
-
Execute the following in the Rails console with the proper id depending on the scope testing:
Group.ids_with_disabled_email(User.first.groups)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #339194 (closed)
Merge request reports
Activity
changed milestone to %14.4
assigned to @fjsanpedro
- A deleted user
added feature flag label
Reviewer roulette
Changes that require review have been detected!
Please refer to the table below for assigning reviewers and maintainers suggested by Danger in the specified category:
Category Reviewer Maintainer backend Marius Bobin ( @mbobin
) (UTC+3, 1 hour ahead of@fjsanpedro
)Etienne Baqué ( @ebaque
) (UTC+3, 1 hour ahead of@fjsanpedro
)To spread load more evenly across eligible reviewers, Danger has picked a candidate for each review slot, based on their timezone. Feel free to override these selections if you think someone else would be better-suited or use the GitLab Review Workload Dashboard to find other available reviewers.
To read more on how to use the reviewer roulette, please take a look at the Engineering workflow and code review guidelines. Please consider assigning a reviewer or maintainer who is a domain expert in the area of the merge request.
Once you've decided who will review this merge request, assign them as a reviewer! Danger does not automatically notify them for you.
If needed, you can retry the
danger-review
job that generated this comment.Generated by
Dangermarked the checklist item I have evaluated the MR acceptance checklist for this MR. as completed
added 1 commit
- 28bdbd05 - Replace Group ancestors scope with linear version
added 1 commit
- d92dd8b9 - Replace Group ancestors scope with linear version
@fjsanpedro, please can you answer the question: Should this have a feature flag? to help with code review for the Access group.This nudge was added by this triage-ops policy.
removed [deprecated] Accepting merge requests label
mentioned in epic &6738 (closed)
added 218 commits
-
d92dd8b9...2428ecbd - 217 commits from branch
master
- a46febf1 - Replace Group ancestors scope with linear version
-
d92dd8b9...2428ecbd - 217 commits from branch
added 135 commits
-
f5277bee...cb39e5bb - 133 commits from branch
master
- 4065a1ec - Replace Group ancestors scope with linear version
- 0994733b - Add roll out issue
-
f5277bee...cb39e5bb - 133 commits from branch
added 189 commits
-
0994733b...092cd22f - 187 commits from branch
master
- 83efcef3 - Replace Group ancestors scope with linear version
- df5235a2 - Add roll out issue
-
0994733b...092cd22f - 187 commits from branch
- Resolved by Fabio Pitino
requested review from @ahegyi
added databaseapproved label
@ahegyi
, thanks for approving this merge request.This is the first time the merge request is approved. To ensure full test coverage, a new pipeline has been started.
For more info, please refer to the following links:
requested review from @alexpooley and removed review request for @ahegyi
added 179 commits
-
df5235a2...91ab9f2a - 177 commits from branch
master
- 08782419 - Replace Group ancestors scope with linear version
- 01118f73 - Add roll out issue
-
df5235a2...91ab9f2a - 177 commits from branch
added 193 commits
-
01118f73...89d2d950 - 192 commits from branch
master
- 68766588 - Replace Group ancestors scope with linear version
-
01118f73...89d2d950 - 192 commits from branch
added 161 commits
-
68766588...da3058d5 - 160 commits from branch
master
- 2e7ea3b6 - Replace Group ancestors scope with linear version
-
68766588...da3058d5 - 160 commits from branch
added 41 commits
-
2e7ea3b6...52e0b948 - 40 commits from branch
master
- bd908d32 - Replace Group ancestors scope with linear version
-
2e7ea3b6...52e0b948 - 40 commits from branch
added typemaintenance label
added typefeature label
requested review from @fabiopitino
enabled an automatic merge when the pipeline for 2fb2f0cb succeeds
mentioned in commit 865cff24
added workflowstaging-canary label
added workflowstaging label and removed workflowstaging-canary label
added workflowcanary label and removed workflowstaging label
added workflowproduction label and removed workflowcanary label
mentioned in epic &5296 (closed)
added releasedcandidate label
mentioned in merge request kubitus-project/kubitus-installer!306 (merged)
removed typefeature label
added releasedpublished label and removed releasedcandidate label