Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ea4cd1d6
Commit
ea4cd1d6
authored
Jan 13, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Destroy user associations in batches
parent
e74f59af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
0 deletions
+24
-0
app/models/user.rb
app/models/user.rb
+1
-0
app/services/users/destroy_service.rb
app/services/users/destroy_service.rb
+7
-0
spec/services/users/destroy_service_spec.rb
spec/services/users/destroy_service_spec.rb
+16
-0
No files found.
app/models/user.rb
View file @
ea4cd1d6
...
...
@@ -20,6 +20,7 @@ class User < ApplicationRecord
include
WithUploads
include
OptionallySearch
include
FromUnion
include
BatchDestroyDependentAssociations
DEFAULT_NOTIFICATION_LEVEL
=
:participating
...
...
app/services/users/destroy_service.rb
View file @
ea4cd1d6
...
...
@@ -56,6 +56,13 @@ module Users
MigrateToGhostUserService
.
new
(
user
).
execute
unless
options
[
:hard_delete
]
if
Feature
.
enabled?
(
:destroy_user_associations_in_batches
)
# Rails attempts to load all related records into memory before
# destroying: https://github.com/rails/rails/issues/22510
# This ensures we delete records in batches.
user
.
destroy_dependent_associations_in_batches
end
# Destroy the namespace after destroying the user since certain methods may depend on the namespace existing
user_data
=
user
.
destroy
namespace
.
destroy
...
...
spec/services/users/destroy_service_spec.rb
View file @
ea4cd1d6
...
...
@@ -20,6 +20,22 @@ describe Users::DestroyService do
expect
{
Namespace
.
find
(
namespace
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
it
'deletes user associations in batches'
do
expect
(
user
).
to
receive
(
:destroy_dependent_associations_in_batches
)
service
.
execute
(
user
)
end
context
'when :destroy_user_associations_in_batches flag is disabled'
do
it
'does not delete user associations in batches'
do
stub_feature_flags
(
destroy_user_associations_in_batches:
false
)
expect
(
user
).
not_to
receive
(
:destroy_dependent_associations_in_batches
)
service
.
execute
(
user
)
end
end
it
'will delete the project'
do
expect_next_instance_of
(
Projects
::
DestroyService
)
do
|
destroy_service
|
expect
(
destroy_service
).
to
receive
(
:execute
).
once
.
and_return
(
true
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment