Skip to content

Use linear version of groups_including_descendants_by

What does this MR do?

In this method we're switching the behavior of the Group#groups_including_descendants_by method to use the linear version. The new behavior is behind the linear_group_including_descendants_by feature flag.

How to setup and validate locally (strongly suggested)

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

SQL Queries

The former query before this change was:

WITH RECURSIVE base_and_descendants AS (
                                          (SELECT namespaces.*
                                           FROM namespaces
                                           WHERE namespaces.type = 'Group'
                                             AND namespaces.id IN (9970,
                                                                   11932235))
                                        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
      WHERE namespaces.type = 'Group'
        AND namespaces.id IN (9970,
                              11932235)) base
   WHERE (namespaces.traversal_ids @> ARRAY[base.id])) namespaces

Does this MR meet the acceptance criteria?

Conformity

Related to #339189 (closed)

Edited by Francisco Javier López

Merge request reports

Loading