Skip to content

Services for persisting Cycle Analytics group stages

Adam Hegyi requested to merge persisting-ca-group-stages into master

What does this MR do?

This change introduces service objects for creating, updating and finding cycle analytics group stages.

The models and validations have been already merged, so this change only contains the service objects. In an upcoming MR these services will be exposed via an API to the fronted.

Specs

Cycle Analytics provides 7 default stages to everyone (FOSS feature), these 7 stages should be available on the group level as well, however reporters should be able to create additional, custom stages.

  Defined for a Group, stored in `analytics_cycle_analytics_group_stages` table.

  +---------------------+
  | Stages              |
  |   +-------------+   |
  |   |   Stage A   |   |     
  |   |             |   |     
  |   +-------------+   |     
  |   | Start Event |   |
  |   +-------------+   |     
  |   | End Event   |   |      
  |   +-------------+   |  
  |                     |
  |   +-------------+   |
  |   |   Stage B   |   |
  |   |             |   |
  |   +-------------+   |
  |   | Start Event |   |
  |   +-------------+   |
  |   | End Event   |   |
  |   +-------------+   |
  |                     |
  |   ...               |
  +---------------------+

Requirements (future):

  • Ability to change the order of stages.
  • Ability to hide a default stage.

To fulfil these requirements, we must also persist the 7 default stages in the database. To keep the record creation at minimum and avoid background migrations, the 7 default stages is going to be persisted as soon as the reporter attempts to make a change to the list of stages (until then, we provide them as in-memory objects):

  • Creating a new, customized stage (for the first time).
  • Hiding a default stage.

Queries

Note 1: this is the first time we query the stages. We have nothing in the prod DB.

Note 2: We expect that a group will have max 10-15 analytics_cycle_analytics_group_stages records (premium only).

Exists Query

SELECT  1 AS one FROM "analytics_cycle_analytics_group_stages" WHERE "analytics_cycle_analytics_group_stages"."group_id" = 15 AND "analytics_cycle_analytics_group_stages"."custom" = true AND "analytics_cycle_analytics_group_stages"."id" != 3 LIMIT 1;

Uses the index

Limit  (cost=0.14..2.17 rows=1 width=4) (actual time=0.007..0.007 rows=0 loops=1)
   ->  Index Scan using index_analytics_ca_group_stages_on_group_id_and_name on analytics_cycle_analytics_group_stages  (cost=0.14..2.17 rows=1 width=4) (actual time=0.006..0.006 rows=0 loops=1)
         Index Cond: (group_id = 15)
         Filter: (custom AND (id <> 3))
 Planning Time: 0.129 ms
 Execution Time: 0.028 ms

Find by name query

SELECT "analytics_cycle_analytics_group_stages".* FROM "analytics_cycle_analytics_group_stages" WHERE "analytics_cycle_analytics_group_stages"."group_id" = 4 AND "analytics_cycle_analytics_group_stages"."name" = 'issue' LIMIT 1;

Uses the index

Limit  (cost=0.14..2.16 rows=1 width=578) (actual time=0.016..0.016 rows=0 loops=1)
   ->  Index Scan using index_analytics_ca_group_stages_on_group_id_and_name on analytics_cycle_analytics_group_stages  (cost=0.14..2.16 rows=1 width=578) (actual time=0.014..0.015 rows=0 loops=1)
         Index Cond: ((group_id = 4) AND ((name)::text = 'issue'::text))
 Planning Time: 0.163 ms
 Execution Time: 0.042 ms
(5 rows)

Screenshots

stages

Does this MR meet the acceptance criteria?

Conformity

closes #32570 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports