Add delay to profile updates to debounce them (#34137)
This commit is contained in:
		@@ -14,7 +14,7 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
 | 
			
		||||
    @account = current_account
 | 
			
		||||
    UpdateAccountService.new.call(@account, account_params, raise_error: true)
 | 
			
		||||
    current_user.update(user_params) if user_params
 | 
			
		||||
    ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
 | 
			
		||||
    ActivityPub::UpdateDistributionWorker.perform_in(ActivityPub::UpdateDistributionWorker::DEBOUNCE_DELAY, @account.id)
 | 
			
		||||
    render json: @account, serializer: REST::CredentialAccountSerializer
 | 
			
		||||
  rescue ActiveRecord::RecordInvalid => e
 | 
			
		||||
    render json: ValidationErrorFormatter.new(e).as_json, status: 422
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ class Api::V1::Profile::AvatarsController < Api::BaseController
 | 
			
		||||
  def destroy
 | 
			
		||||
    @account = current_account
 | 
			
		||||
    UpdateAccountService.new.call(@account, { avatar: nil }, raise_error: true)
 | 
			
		||||
    ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
 | 
			
		||||
    ActivityPub::UpdateDistributionWorker.perform_in(ActivityPub::UpdateDistributionWorker::DEBOUNCE_DELAY, @account.id)
 | 
			
		||||
    render json: @account, serializer: REST::CredentialAccountSerializer
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ class Api::V1::Profile::HeadersController < Api::BaseController
 | 
			
		||||
  def destroy
 | 
			
		||||
    @account = current_account
 | 
			
		||||
    UpdateAccountService.new.call(@account, { header: nil }, raise_error: true)
 | 
			
		||||
    ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
 | 
			
		||||
    ActivityPub::UpdateDistributionWorker.perform_in(ActivityPub::UpdateDistributionWorker::DEBOUNCE_DELAY, @account.id)
 | 
			
		||||
    render json: @account, serializer: REST::CredentialAccountSerializer
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ module Settings
 | 
			
		||||
    def destroy
 | 
			
		||||
      if valid_picture?
 | 
			
		||||
        if UpdateAccountService.new.call(@account, { @picture => nil, "#{@picture}_remote_url" => '' })
 | 
			
		||||
          ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
 | 
			
		||||
          ActivityPub::UpdateDistributionWorker.perform_in(ActivityPub::UpdateDistributionWorker::DEBOUNCE_DELAY, @account.id)
 | 
			
		||||
          redirect_to settings_profile_path, notice: I18n.t('generic.changes_saved_msg'), status: 303
 | 
			
		||||
        else
 | 
			
		||||
          redirect_to settings_profile_path
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ class Settings::PrivacyController < Settings::BaseController
 | 
			
		||||
  def update
 | 
			
		||||
    if UpdateAccountService.new.call(@account, account_params.except(:settings))
 | 
			
		||||
      current_user.update!(settings_attributes: account_params[:settings])
 | 
			
		||||
      ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
 | 
			
		||||
      ActivityPub::UpdateDistributionWorker.perform_in(ActivityPub::UpdateDistributionWorker::DEBOUNCE_DELAY, @account.id)
 | 
			
		||||
      redirect_to settings_privacy_path, notice: I18n.t('generic.changes_saved_msg')
 | 
			
		||||
    else
 | 
			
		||||
      render :show
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ class Settings::ProfilesController < Settings::BaseController
 | 
			
		||||
 | 
			
		||||
  def update
 | 
			
		||||
    if UpdateAccountService.new.call(@account, account_params)
 | 
			
		||||
      ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
 | 
			
		||||
      ActivityPub::UpdateDistributionWorker.perform_in(ActivityPub::UpdateDistributionWorker::DEBOUNCE_DELAY, @account.id)
 | 
			
		||||
      redirect_to settings_profile_path, notice: I18n.t('generic.changes_saved_msg')
 | 
			
		||||
    else
 | 
			
		||||
      @account.build_fields
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ class Settings::VerificationsController < Settings::BaseController
 | 
			
		||||
 | 
			
		||||
  def update
 | 
			
		||||
    if UpdateAccountService.new.call(@account, account_params)
 | 
			
		||||
      ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
 | 
			
		||||
      ActivityPub::UpdateDistributionWorker.perform_in(ActivityPub::UpdateDistributionWorker::DEBOUNCE_DELAY, @account.id)
 | 
			
		||||
      redirect_to settings_verification_path, notice: I18n.t('generic.changes_saved_msg')
 | 
			
		||||
    else
 | 
			
		||||
      render :show
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user