Use `dependent: :destroy_async` instead of `DeletionWorker`

This commit is contained in:
Karina Kwiatek 2022-02-04 21:09:43 +01:00 committed by Karina Kwiatek
parent 0db369a9ae
commit e7112f0244
4 changed files with 21 additions and 36 deletions

View File

@ -8,8 +8,8 @@ class User::RegistrationsController < Devise::RegistrationsController
end
def destroy
DeletionWorker.perform_async(resource.id)
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
resource.destroy
set_flash_message :notice, :destroyed if is_flashing_format?
yield resource if block_given?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }

View File

@ -27,28 +27,28 @@ class User < ApplicationRecord
# attr_accessor :login
has_many :questions, dependent: :destroy
has_many :answers, dependent: :destroy
has_many :comments, dependent: :destroy
has_many :inboxes, dependent: :destroy
has_many :smiles, class_name: "Appendable::Reaction", dependent: :destroy
has_many :services, dependent: :destroy
has_many :notifications, foreign_key: :recipient_id, dependent: :destroy
has_many :reports, dependent: :destroy
has_many :moderation_comments, dependent: :destroy
has_many :moderation_votes, dependent: :destroy
has_many :lists, dependent: :destroy
has_many :list_memberships, class_name: "ListMember", foreign_key: 'user_id', dependent: :destroy
has_many :mute_rules, dependent: :destroy
has_many :anonymous_blocks, dependent: :destroy
has_many :questions, dependent: :destroy_async
has_many :answers, dependent: :destroy_async
has_many :comments, dependent: :destroy_async
has_many :inboxes, dependent: :destroy_async
has_many :smiles, class_name: "Appendable::Reaction", dependent: :destroy_async
has_many :services, dependent: :destroy_async
has_many :notifications, foreign_key: :recipient_id, dependent: :destroy_async
has_many :reports, dependent: :destroy_async
has_many :moderation_comments, dependent: :destroy_async
has_many :moderation_votes, dependent: :destroy_async
has_many :lists, dependent: :destroy_async
has_many :list_memberships, class_name: "ListMember", foreign_key: 'user_id', dependent: :destroy_async
has_many :mute_rules, dependent: :destroy_async
has_many :anonymous_blocks, dependent: :destroy_async
has_many :subscriptions, dependent: :destroy
has_many :totp_recovery_codes, dependent: :destroy
has_many :subscriptions, dependent: :destroy_async
has_many :totp_recovery_codes, dependent: :destroy_async
has_one :profile, dependent: :destroy
has_one :theme, dependent: :destroy
has_one :profile, dependent: :destroy_async
has_one :theme, dependent: :destroy_async
has_many :bans, class_name: 'UserBan', dependent: :destroy
has_many :bans, class_name: 'UserBan', dependent: :destroy_async
has_many :banned_users, class_name: 'UserBan',
foreign_key: 'banned_by_id',
dependent: :nullify

View File

@ -1,15 +0,0 @@
class DeletionWorker
include Sidekiq::Worker
sidekiq_options queue: :deletion, retry: false
# @param resource_id [Integer] user id passed from Devise
def perform(resource_id)
begin
User.find(resource_id).destroy!
rescue => e
logger.info "failed to delete user: #{e.message}"
Sentry.capture_exception(e)
end
end
end

View File

@ -6,10 +6,10 @@ staging:
production:
:concurrency: 25
:queues:
- default
- share
- carrierwave
- mailers
- deletion
- question
- export