|
|
|
@ -276,6 +276,9 @@ class MediaAttachment < ApplicationRecord
|
|
|
|
|
before_create :set_unknown_type
|
|
|
|
|
before_create :set_processing
|
|
|
|
|
|
|
|
|
|
before_destroy :prepare_cache_bust!, prepend: true
|
|
|
|
|
after_destroy :bust_cache!
|
|
|
|
|
|
|
|
|
|
after_commit :enqueue_processing, on: :create
|
|
|
|
|
after_commit :reset_parent_cache, on: :update
|
|
|
|
|
|
|
|
|
@ -410,4 +413,29 @@ class MediaAttachment < ApplicationRecord
|
|
|
|
|
def reset_parent_cache
|
|
|
|
|
Rails.cache.delete("v3:statuses/#{status_id}") if status_id.present?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Record the cache keys to burst before the file get actually deleted
|
|
|
|
|
def prepare_cache_bust!
|
|
|
|
|
return unless Rails.configuration.x.cache_buster_enabled
|
|
|
|
|
|
|
|
|
|
@paths_to_cache_bust = MediaAttachment.attachment_definitions.keys.flat_map do |attachment_name|
|
|
|
|
|
attachment = public_send(attachment_name)
|
|
|
|
|
styles = DEFAULT_STYLES | attachment.styles.keys
|
|
|
|
|
styles.map { |style| attachment.path(style) }
|
|
|
|
|
end
|
|
|
|
|
rescue => e
|
|
|
|
|
# We really don't want any error here preventing media deletion
|
|
|
|
|
Rails.logger.warn "Error #{e.class} busting cache: #{e.message}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Once Paperclip has deleted the files, we can't recover the cache keys,
|
|
|
|
|
# so use the previously-saved ones
|
|
|
|
|
def bust_cache!
|
|
|
|
|
return unless Rails.configuration.x.cache_buster_enabled
|
|
|
|
|
|
|
|
|
|
CacheBusterWorker.push_bulk(@paths_to_cache_bust) { |path| [path] }
|
|
|
|
|
rescue => e
|
|
|
|
|
# We really don't want any error here preventing media deletion
|
|
|
|
|
Rails.logger.warn "Error #{e.class} busting cache: #{e.message}"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|