Skip to content

API for user groups count

Aishwarya Subramanian requested to merge 249589-group-count into master

What does this MR do?

This MR creates an admin api to return the Group count for a list of users.

The api will be invoked asynchronously in the Admin Users dashboard.

The rationale behind this choice of design is mentioned in the POC.

Query:
SELECT
  COUNT(*) AS count_all,
  "user_id" AS user_id
FROM ((
    SELECT
      namespaces.*,
      members.user_id AS user_id
    FROM
      "namespaces"
      INNER JOIN "members" ON "members"."source_type" = 'Namespace'
        AND "members"."source_type" = 'Namespace'
        AND "members"."requested_at" IS NULL
        AND "members"."access_level" != 5
        AND "members"."source_id" = "namespaces"."id"
        AND "members"."type" = 'GroupMember'
    WHERE
      "namespaces"."type" = 'Group'
      AND (members.user_id IN (200, 401, 1003, 40098, 432190, 4456462, 135664, 3432534, 3231111, 35656, 21212, 435436, 325452, 1234132, 5654767, 5647634, 56266, 324325, 254356, 6578356, 201, 402, 1004, 40099, 432191, 4456463, 135665, 3432535, 3231112, 35657, 21213, 435437, 325453, 1234133, 5654768, 5647635, 56267, 324326, 254357, 6578357, 202, 403, 1005, 40092, 432192, 4456464, 135666, 3432536, 3231113, 35658, 21214, 435438, 325454, 1234134, 5654799, 5647636, 56268, 324327, 254358, 6578358, 203, 404, 1006, 40093, 432193, 4456465, 135667, 3432537, 3231114, 35659, 21215, 435439, 325455, 1234135, 5654760, 5647637, 56269, 324328, 254359, 6578359, 204, 405, 1007, 40094, 432194, 4456466, 135668, 3432538, 3231115, 35650, 21216, 435430, 325456, 1234136, 5654762, 5647638, 56260, 324329, 254350, 6578351))
      AND (access_level >= 10))
  UNION (
    SELECT
      namespaces.*,
      project_authorizations.user_id AS user_id
    FROM
      "namespaces"
      INNER JOIN "projects" ON "projects"."namespace_id" = "namespaces"."id"
      INNER JOIN "project_authorizations" ON "project_authorizations"."project_id" = "projects"."id"
    WHERE
      "namespaces"."type" = 'Group'
      AND (project_authorizations.user_id IN (200, 401, 1003, 40098, 432190, 4456462, 135664, 3432534, 3231111, 35656, 21212, 435436, 325452, 1234132, 5654767, 5647634, 56266, 324325, 254356, 6578356, 201, 402, 1004, 40099, 432191, 4456463, 135665, 3432535, 3231112, 35657, 21213, 435437, 325453, 1234133, 5654768, 5647635, 56267, 324326, 254357, 6578357, 202, 403, 1005, 40092, 432192, 4456464, 135666, 3432536, 3231113, 35658, 21214, 435438, 325454, 1234134, 5654799, 5647636, 56268, 324327, 254358, 6578358, 203, 404, 1006, 40093, 432193, 4456465, 135667, 3432537, 3231114, 35659, 21215, 435439, 325455, 1234135, 5654760, 5647637, 56269, 324328, 254359, 6578359, 204, 405, 1007, 40094, 432194, 4456466, 135668, 3432538, 3231115, 35650, 21216, 435430, 325456, 1234136, 5654762, 5647638, 56260, 324329, 254350, 6578351)))) namespaces
GROUP BY
  "user_id";

Execution plan: https://explain.depesz.com/s/opqDh

Time: 3.807 s
  - planning: 5.580 ms
  - execution: 3.802 s
    - I/O read: 3.722 s
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 5890 (~46.00 MiB) from the buffer pool
  - reads: 2297 (~17.90 MiB) from the OS file cache, including disk I/O
  - dirtied: 47 (~376.00 KiB)
  - writes: 0

Mentions #249589 (closed)

Screenshots

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

Closes #249589 (closed)

Edited by Aishwarya Subramanian

Merge request reports