Skip to content

Cleanup unaccessible todos when user leaves public project

What does this MR do and why?

Changes the way we cleanup unaccessible TODOs when user leaves public project. Previous implementation had outdated rules and was deleting the data which shouldn't be deleted or other way around.

Migration & queries

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/7449/commands/26410

== 20211125120444 AddIndexTodosProjectIdUserId: reverting =====================
-- transaction_open?()
   -> 0.0000s
-- indexes(:todos)
   -> 0.0182s
-- remove_index(:todos, {:algorithm=>:concurrently, :name=>"index_todos_on_project_id_and_user_id_and_id"})
   -> 0.0040s
== 20211125120444 AddIndexTodosProjectIdUserId: reverted (0.0275s) ============

== 20211125120444 AddIndexTodosProjectIdUserId: migrating =====================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:todos, [:project_id, :user_id, :id], {:name=>"index_todos_on_project_id_and_user_id_and_id", :algorithm=>:concurrently})
   -> 0.0240s
-- add_index(:todos, [:project_id, :user_id, :id], {:name=>"index_todos_on_project_id_and_user_id_and_id", :algorithm=>:concurrently})
   -> 0.0130s
== 20211125120444 AddIndexTodosProjectIdUserId: migrated (0.0420s) ============

Index creation takes ~10 minutes in DB lab.

== 20211202145237 AddTodosProjectAndIdIndex: reverting ========================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:todos, :project_id, {:name=>"index_todos_on_project_id", :algorithm=>:concurrently})
   -> 0.0535s
-- add_index(:todos, :project_id, {:name=>"index_todos_on_project_id", :algorithm=>:concurrently})
   -> 0.0249s
-- transaction_open?()
   -> 0.0000s
-- indexes(:todos)
   -> 0.0664s
-- remove_index(:todos, {:algorithm=>:concurrently, :name=>"index_todos_on_project_id_and_id"})
   -> 0.0159s
== 20211202145237 AddTodosProjectAndIdIndex: reverted (0.1896s) ===============

== 20211202145237 AddTodosProjectAndIdIndex: migrating ========================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:todos, [:project_id, :id], {:name=>"index_todos_on_project_id_and_id", :algorithm=>:concurrently})
   -> 0.0245s
-- add_index(:todos, [:project_id, :id], {:name=>"index_todos_on_project_id_and_id", :algorithm=>:concurrently})
   -> 0.0133s
-- transaction_open?()
   -> 0.0000s
-- indexes(:todos)
   -> 0.0262s
-- remove_index(:todos, {:algorithm=>:concurrently, :name=>"index_todos_on_project_id"})
   -> 0.0046s
== 20211202145237 AddTodosProjectAndIdIndex: migrated (0.0795s) ===============

How to set up and validate locally

  1. Create public project with issues set to private
  2. Invite user A to a project above
  3. Create an issue, add a TODO for user A for this issue
  4. As user A leave project
  5. Run background jobs
  6. Verify that user A has no TODO assigned for issue in UI and DB.

See #325422 (closed) for more info

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #325422 (closed)

Edited by Pavel Shutsin

Merge request reports