From df1653174be233f2737d8ec281325dee54011947 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 19 Nov 2020 17:38:06 +0100 Subject: Add cache buster feature for media files (#15155) Nginx can be configured to bypass proxy cache when a special header is in the request. If the response is cacheable, it will replace the cache for that request. Proxy caching of media files is desirable when using object storage as a way of minimizing bandwidth costs, but has the drawback of leaving deleted media files for a configured amount of cache time. A cache buster can make those media files immediately unavailable. This especially makes sense when suspending and unsuspending an account. --- app/workers/cache_buster_worker.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/workers/cache_buster_worker.rb (limited to 'app/workers') diff --git a/app/workers/cache_buster_worker.rb b/app/workers/cache_buster_worker.rb new file mode 100644 index 000000000..5ad0a44cb --- /dev/null +++ b/app/workers/cache_buster_worker.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CacheBusterWorker + include Sidekiq::Worker + include RoutingHelper + + sidekiq_options queue: 'pull' + + def perform(path) + cache_buster.bust(full_asset_url(path)) + end + + private + + def cache_buster + CacheBuster.new(Rails.configuration.x.cache_buster) + end +end -- cgit From 2f6831f3187af0dfd9cacd7d4cba5664be7a9cbd Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 19 Nov 2020 17:39:47 +0100 Subject: Fix sending spurious Rejects when processing remote account deletion (#15104) * Fix sending spurious Rejects when processing remote account deletion * Make skip_side_effects imply skip_activitypub --- app/lib/activitypub/activity/delete.rb | 2 +- app/services/delete_account_service.rb | 5 ++++- app/services/resolve_account_service.rb | 2 +- app/workers/account_deletion_worker.rb | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'app/workers') diff --git a/app/lib/activitypub/activity/delete.rb b/app/lib/activitypub/activity/delete.rb index 09b9e5e0e..2e5293b83 100644 --- a/app/lib/activitypub/activity/delete.rb +++ b/app/lib/activitypub/activity/delete.rb @@ -13,7 +13,7 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity def delete_person lock_or_return("delete_in_progress:#{@account.id}") do - DeleteAccountService.new.call(@account, reserve_username: false) + DeleteAccountService.new.call(@account, reserve_username: false, skip_activitypub: true) end end diff --git a/app/services/delete_account_service.rb b/app/services/delete_account_service.rb index de6488c78..778d064de 100644 --- a/app/services/delete_account_service.rb +++ b/app/services/delete_account_service.rb @@ -41,6 +41,7 @@ class DeleteAccountService < BaseService # @option [Boolean] :reserve_email Keep user record. Only applicable for local accounts # @option [Boolean] :reserve_username Keep account record # @option [Boolean] :skip_side_effects Side effects are ActivityPub and streaming API payloads + # @option [Boolean] :skip_activitypub Skip sending ActivityPub payloads. Implied by :skip_side_effects # @option [Time] :suspended_at Only applicable when :reserve_username is true def call(account, **options) @account = account @@ -52,6 +53,8 @@ class DeleteAccountService < BaseService @options[:skip_side_effects] = true end + @options[:skip_activitypub] = true if @options[:skip_side_effects] + reject_follows! purge_user! purge_profile! @@ -62,7 +65,7 @@ class DeleteAccountService < BaseService private def reject_follows! - return if @account.local? || !@account.activitypub? + return if @account.local? || !@account.activitypub? || @options[:skip_activitypub] # When deleting a remote account, the account obviously doesn't # actually become deleted on its origin server, i.e. unlike a diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb index 4783e6d33..c5291fa67 100644 --- a/app/services/resolve_account_service.rb +++ b/app/services/resolve_account_service.rb @@ -145,7 +145,7 @@ class ResolveAccountService < BaseService end def queue_deletion! - AccountDeletionWorker.perform_async(@account.id, reserve_username: false) + AccountDeletionWorker.perform_async(@account.id, reserve_username: false, skip_activitypub: true) end def lock_options diff --git a/app/workers/account_deletion_worker.rb b/app/workers/account_deletion_worker.rb index 81c3b91ad..98b67419d 100644 --- a/app/workers/account_deletion_worker.rb +++ b/app/workers/account_deletion_worker.rb @@ -7,7 +7,8 @@ class AccountDeletionWorker def perform(account_id, options = {}) reserve_username = options.with_indifferent_access.fetch(:reserve_username, true) - DeleteAccountService.new.call(Account.find(account_id), reserve_username: reserve_username, reserve_email: false) + skip_activitypub = options.with_indifferent_access.fetch(:skip_activitypub, false) + DeleteAccountService.new.call(Account.find(account_id), reserve_username: reserve_username, skip_activitypub: skip_activitypub, reserve_email: false) rescue ActiveRecord::RecordNotFound true end -- cgit