Skip to content

Use linear version of User#membership_groups

What does this MR do?

In this method we're switching the behavior of the User#membership_groups method to use the linear version. The new behavior is behind the linear_user_membership_groups feature flag.

How to setup and validate locally (strongly suggested)

  1. Enable the new method behavior feature flag
    Feature.enable(:linear_user_membership_groups)
  2. In rails console enable the traversal id feature flag
    Feature.enable(:use_traversal_ids)

SQL Queries

The query before the changes was:

WITH RECURSIVE base_and_descendants AS (
                                          (SELECT namespaces.*
                                           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 = 1
                                             AND members.requested_at IS NULL
                                             AND (access_level >= 10))
                                        UNION
                                          (SELECT namespaces.*
                                           FROM namespaces,
                                                base_and_descendants
                                           WHERE namespaces.type = 'Group'
                                             AND namespaces.parent_id = base_and_descendants.id))
SELECT namespaces.*
FROM base_and_descendants AS namespaces

The new query is:

SELECT namespaces.*
FROM
  (SELECT DISTINCT on(namespaces.id) namespaces.*
   FROM namespaces,

     (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 = 1
        AND members.requested_at IS NULL
        AND (access_level >= 10)) base
   WHERE (namespaces.traversal_ids @> ARRAY[base.id])) namespaces

Does this MR meet the acceptance criteria?

Conformity

Related to #339195 (closed)

Merge request reports