Skip to content

Expose stage counts in VSA

Adam Hegyi requested to merge 324687-expose-limited-record-count-in-vsa into master

What does this MR do?

This MR exposes the MR or Issue count for each stage. The count is using a limit, so we query maximum 1001 rows.

The frontend will process the count by these rules:

  • If count < 1001, show the actual count
  • If count = 1001, show 1000+

How to test it:

  1. Make sure you have ultimate license
  2. Seed a new VSA group: SEED_VSA=true FILTER=cycle_analytics rake db:seed_fu
  3. Visit the group page
  4. Go to Analytics -> Value Stream
  5. Open the network inspector and search for median
  6. Copy the request URL and replace median with count
  7. { count: number } should show up in the response

Database

The query suffers from the same problem like other VSA (and group level queries). Getting the group hierarchy and read too much data.

SELECT COUNT(*)
FROM
  (SELECT 1 AS one
   FROM "issues"
   INNER JOIN "projects" ON "projects"."id" = "issues"."project_id"
   INNER JOIN "issue_metrics" ON "issue_metrics"."issue_id" = "issues"."id"
   LEFT JOIN project_features ON projects.id = project_features.project_id
   WHERE "projects"."namespace_id" IN
       (SELECT "namespaces"."id"
        FROM
          (SELECT "namespaces".*
           FROM "namespaces"
           INNER JOIN
             (SELECT "id",
                     "depth"
              FROM
                (WITH RECURSIVE "base_and_descendants" AS (
                                                             (SELECT "namespaces".*
                                                              FROM "namespaces"
                                                              WHERE "namespaces"."type" = 'Group'
                                                                AND "namespaces"."id" = 9970)
                                                           UNION
                                                             (SELECT "namespaces".*
                                                              FROM "namespaces",
                                                                   "base_and_descendants"
                                                              WHERE "namespaces"."type" = 'Group'
                                                                AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT DISTINCT "namespaces".*,
                                                                                                                                             ROW_NUMBER() OVER () AS depth
                 FROM "base_and_descendants" AS "namespaces") AS "namespaces"
              WHERE "namespaces"."type" = 'Group') namespaces_join_table ON namespaces_join_table.id = namespaces.id
           WHERE "namespaces"."type" = 'Group'
           ORDER BY "namespaces_join_table"."depth" ASC) AS "namespaces"
        WHERE "namespaces"."type" = 'Group')
     AND (EXISTS
            (SELECT 1
             FROM "project_authorizations"
             WHERE "project_authorizations"."user_id" = 4156052
               AND (project_authorizations.project_id = projects.id))
          OR projects.visibility_level IN (0,
                                           10,
                                           20))
     AND ("project_features"."issues_access_level" > 0
          OR "project_features"."issues_access_level" IS NULL)
     AND "issues"."created_at" <= '2021-04-19 23:59:59.999999'
     AND "issues"."created_at" >= '2021-03-19 00:00:00'
     AND "issue_metrics"."first_mentioned_in_commit_at" >= "issue_metrics"."first_added_to_board_at"
   ORDER BY "issues"."id" DESC
   LIMIT 1001) subquery_for_count

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

Related to #324687 (closed)

Edited by Adam Hegyi

Merge request reports