Expose stage counts in VSA
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:
- Make sure you have ultimate license
- Seed a new VSA group:
SEED_VSA=true FILTER=cycle_analytics rake db:seed_fu
- Visit the group page
- Go to Analytics -> Value Stream
- Open the network inspector and search for
median
- Copy the request URL and replace
median
withcount
-
{ 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
- Uncached plan: https://explain.depesz.com/s/aOTc
- Cached plan: https://explain.depesz.com/s/HZtR
- PG AI: https://explain.depesz.com/s/ukON
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because not user facing change (FE part missing).
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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