Skip to content
代码片段 群组 项目
未验证 提交 aa50e780 编辑于 作者: Lukas Eipert's avatar Lukas Eipert 提交者: GitLab
浏览文件

Migrate authored todos to GhostUser

Currently, when a user is deleted, we destroy all todos they authored.
It might preferable to change them to the GhostUser, similar to what we
do with Issues, Notes or UserAwards. Just because a user is deleted, it
should not affect my todos.

Hopefully this should fix the problems we are seeing with performance as
well, as the updates are executed in a loop until all todos are
migrated.

Note: In this commit we migrate todos to the GhostUser even if the
hard_delete is set.

See also:
- https://gitlab.com/gitlab-com/gl-infra/production/-/issues/19169
- https://gitlab.com/gitlab-org/gitlab/-/issues/515442

Changelog: changed
上级 a221bb49
No related branches found
No related tags found
无相关合并请求
......@@ -37,6 +37,7 @@ def migrate_records
return if hard_delete
migrate_authored_todos
migrate_issues
migrate_merge_requests
migrate_notes
......@@ -68,6 +69,10 @@ def delete_snippets
raise DestroyError, response.message if response.error?
end
def migrate_authored_todos
batched_migrate(Todo, :author_id)
end
def migrate_issues
batched_migrate(Issue, :author_id)
batched_migrate(Issue, :last_edited_by_id)
......
......@@ -140,6 +140,21 @@
end
end
context 'for todos' do
include_examples 'migrating records to the ghost user', Todo, [:author] do
let(:issue) { create(:issue, project: project, author: user) }
let(:created_record) do
create(
:todo,
project: issue.project,
user: create(:user),
author: user,
target: issue
)
end
end
end
context 'for releases' do
include_examples 'migrating records to the ghost user', Release, [:author] do
let(:created_record) { create(:release, author: user) }
......@@ -208,7 +223,7 @@ def nullify_in_batches_regexp(table, column, user, batch_size: 100)
created_project = create(:project, creator: user)
# associations to be destroyed
todos = create_list(:todo, 2, project: issue.project, user: user, author: user, target: issue)
todos = create_list(:todo, 2, project: issue.project, user: user, author: create(:user), target: issue)
event = create(:event, project: issue.project, author: user)
query_recorder = ActiveRecord::QueryRecorder.new do
......@@ -225,7 +240,6 @@ def nullify_in_batches_regexp(table, column, user, batch_size: 100)
expect(resource_label_event.user_id).to be_nil
expect(resource_state_event.user_id).to be_nil
expect(created_project.creator_id).to be_nil
expect(user.authored_todos).to be_empty
expect(user.todos).to be_empty
expect(user.authored_events).to be_empty
......@@ -238,7 +252,6 @@ def nullify_in_batches_regexp(table, column, user, batch_size: 100)
]
expected_queries += delete_in_batches_regexps(:todos, :user_id, user, todos)
expected_queries += delete_in_batches_regexps(:todos, :author_id, user, todos)
expected_queries += delete_in_batches_regexps(:events, :author_id, user, [event])
expect(query_recorder.log).to include(*expected_queries)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册