Skip to content

#214581 Add delete metrics user starred dashboard service

What does this MR do?

This MR is a part of #214581 (closed) it adds new service which locates metrics_users_starred_dashboards records which belongs to selected user (scoped to project, and dashboard) and deletes them. This is only backstage change, so no changelog entry is required at this point

Database

gitlabhq_development=# SELECT * FROM metrics_users_starred_dashboards LIMIT 5;
  id |          created_at           |          updated_at           | project_id | user_id | dashboard_path
----+-------------------------------+-------------------------------+------------+---------+----------------
1 | 2020-04-30 10:41:17.097841+02 | 2020-04-30 10:41:17.097842+02 |         16 |       2 | dashboard_0_0
2 | 2020-04-30 10:41:17.097849+02 | 2020-04-30 10:41:17.09785+02  |         12 |      27 | dashboard_0_1
3 | 2020-04-30 10:41:17.097855+02 | 2020-04-30 10:41:17.097856+02 |         11 |      43 | dashboard_0_2
4 | 2020-04-30 10:41:17.097861+02 | 2020-04-30 10:41:17.097862+02 |          4 |      40 | dashboard_0_3
5 | 2020-04-30 10:41:17.097867+02 | 2020-04-30 10:41:17.097867+02 |         10 |      34 | dashboard_0_4
(5 rows)

gitlabhq_development=# SELECT COUNT(*) FROM metrics_users_starred_dashboards;
  count
---------
1010103
(1 row)

gitlabhq_development=# EXPLAIN (ANALYZE, BUFFERS) DELETE FROM "metrics_users_starred_dashboards" WHERE "metrics_users_starred_dashboards"."user_id" = 2 AND "metrics_users_starred_dashboards"."project_id" = 16;
  QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Delete on metrics_users_starred_dashboards  (cost=0.42..1242.24 rows=1267 width=6) (actual time=5.024..5.024 rows=0 loops=1)
Buffers: shared hit=2550 dirtied=104
->  Index Scan using idx_metrics_users_starred_dashboard_on_user_project_dashboard on metrics_users_starred_dashboards  (cost=0.42..1242.24 rows=1267 width=6) (actual time=0.020..4.301 rows=1300 loops=1)
Index Cond: ((user_id = 2) AND (project_id = 16))
Buffers: shared hit=1250 dirtied=104
Planning time: 0.076 ms
Execution time: 5.043 ms


gitlabhq_development=# EXPLAIN (ANALYZE, BUFFERS) DELETE FROM "metrics_users_starred_dashboards" WHERE "metrics_users_starred_dashboards"."user_id" = 2 AND "metrics_users_starred_dashboards"."project_id" = 16 AND "metrics_users_starred_dashboards"."dashboard_path" = 'dashboard_0_0';
  QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Delete on metrics_users_starred_dashboards  (cost=0.42..2.45 rows=1 width=6) (actual time=0.036..0.036 rows=0 loops=1)
Buffers: shared hit=5
->  Index Scan using idx_metrics_users_starred_dashboard_on_user_project_dashboard on metrics_users_starred_dashboards  (cost=0.42..2.45 rows=1 width=6) (actual time=0.017..0.018 rows=1 loops=1)
Index Cond: ((user_id = 2) AND (project_id = 16) AND (dashboard_path = 'dashboard_0_0'::text))
Buffers: shared hit=4
Planning time: 0.092 ms
Execution time: 0.058 ms
(7 rows)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Edited by 🤖 GitLab Bot 🤖

Merge request reports