From f06fa099625e928e5858ea81a20be1eddf6c6fbb Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 21 Aug 2018 17:53:01 +0200 Subject: [PATCH] Revert to using Paperclip's filesystem storage, and fix dangling records in remove_remote (#8339) * Fix uncaching worker * Revert to using Paperclip's filesystem backend instead of fog-local fog-local has lots of concurrency issues, causing failure to delete files, dangling file records, and spurious errors UncacheMediaWorker --- Gemfile | 1 - Gemfile.lock | 3 --- app/workers/maintenance/uncache_media_worker.rb | 2 +- config/initializers/paperclip.rb | 12 ++++-------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 31c3c8086..516d397a2 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,6 @@ gem 'dotenv-rails', '~> 2.2', '< 2.3' gem 'aws-sdk-s3', '~> 1.9', require: false gem 'fog-core', '~> 1.45' -gem 'fog-local', '~> 0.5', require: false gem 'fog-openstack', '~> 0.1', require: false gem 'paperclip', '~> 6.0' gem 'paperclip-av-transcoder', '~> 0.6' diff --git a/Gemfile.lock b/Gemfile.lock index fbffc0c2d..ea0e3f0cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -220,8 +220,6 @@ GEM fog-json (1.0.2) fog-core (~> 1.0) multi_json (~> 1.10) - fog-local (0.5.0) - fog-core (>= 1.27, < 3.0) fog-openstack (0.1.25) fog-core (~> 1.40) fog-json (>= 1.0) @@ -679,7 +677,6 @@ DEPENDENCIES fast_blank (~> 1.0) fastimage fog-core (~> 1.45) - fog-local (~> 0.5) fog-openstack (~> 0.1) fuubar (~> 2.2) goldfinger (~> 2.1) diff --git a/app/workers/maintenance/uncache_media_worker.rb b/app/workers/maintenance/uncache_media_worker.rb index f6a51a1b8..2d1a670a7 100644 --- a/app/workers/maintenance/uncache_media_worker.rb +++ b/app/workers/maintenance/uncache_media_worker.rb @@ -8,7 +8,7 @@ class Maintenance::UncacheMediaWorker def perform(media_attachment_id) media = MediaAttachment.find(media_attachment_id) - return unless media.file.exists? + return if media.file.blank? media.file.destroy media.save diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index c134bc5b8..59ab9b9a1 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -74,14 +74,10 @@ elsif ENV['SWIFT_ENABLED'] == 'true' fog_public: true ) else - require 'fog/local' - Paperclip::Attachment.default_options.merge!( - fog_credentials: { - provider: 'Local', - local_root: ENV.fetch('PAPERCLIP_ROOT_PATH') { Rails.root.join('public', 'system') }, - }, - fog_directory: '', - fog_host: ENV.fetch('PAPERCLIP_ROOT_URL') { '/system' } + storage: :filesystem, + use_timestamp: true, + path: (ENV['PAPERCLIP_ROOT_PATH'] || ':rails_root/public/system') + '/:class/:attachment/:id_partition/:style/:filename', + url: (ENV['PAPERCLIP_ROOT_URL'] || '/system') + '/:class/:attachment/:id_partition/:style/:filename', ) end