From d185c54f0387ae1a69b137ea1df9e51eb077b1b6 Mon Sep 17 00:00:00 2001 From: "Dominik M. Kwiatek" Date: Sun, 17 May 2020 19:58:27 +0100 Subject: [PATCH] Add CarrierWave Backgrounder --- Gemfile | 1 + Gemfile.lock | 9 +++++++++ app/models/user.rb | 2 ++ app/uploaders/base_uploader.rb | 1 + config/initializers/25_carrierwave.rb | 6 +++++- config/sidekiq.yml | 2 +- db/schema.rb | 6 +++--- 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 4cdc790d..37b47643 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,7 @@ gem 'tiny-color-rails' gem 'jquery-minicolors-rails' gem 'colorize' gem 'carrierwave', '~> 2.0' +gem 'carrierwave_backgrounder', git: 'https://github.com/mltnhm/carrierwave_backgrounder.git' gem 'mini_magick' gem "rolify", "~> 5.2" diff --git a/Gemfile.lock b/Gemfile.lock index d97927bc..adfbad52 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,6 +10,14 @@ GIT oauth simple_oauth +GIT + remote: https://github.com/mltnhm/carrierwave_backgrounder.git + revision: 8fe468957f047ad7039f07679e5952a534d07b6d + specs: + carrierwave_backgrounder (0.4.2) + carrierwave (>= 0.5, <= 2.1) + mime-types (>= 3.0.0) + GIT remote: https://github.com/retrospring/questiongenerator.git revision: c5f8362ff769425d42a94b3a611731eadaa5e0ca @@ -527,6 +535,7 @@ DEPENDENCIES byebug capybara carrierwave (~> 2.0) + carrierwave_backgrounder! coffee-rails (~> 4.1) colorize database_cleaner diff --git a/app/models/user.rb b/app/models/user.rb index adb2e439..23330b3c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -58,7 +58,9 @@ class User < ApplicationRecord validates :bio, length: { maximum: 200 } mount_uploader :profile_picture, ProfilePictureUploader, mount_on: :profile_picture_file_name + process_in_background :profile_picture mount_uploader :profile_header, ProfileHeaderUploader, mount_on: :profile_header_file_name + process_in_background :profile_header before_save do self.website = if website.match %r{\Ahttps?://} diff --git a/app/uploaders/base_uploader.rb b/app/uploaders/base_uploader.rb index a15ef68e..dfa3ecab 100644 --- a/app/uploaders/base_uploader.rb +++ b/app/uploaders/base_uploader.rb @@ -1,6 +1,7 @@ class BaseUploader < CarrierWave::Uploader::Base include CarrierWave::Compatibility::Paperclip include CarrierWave::MiniMagick + include CarrierWave::Backgrounder::Delay storage :fog diff --git a/config/initializers/25_carrierwave.rb b/config/initializers/25_carrierwave.rb index 754abd4e..d524287d 100644 --- a/config/initializers/25_carrierwave.rb +++ b/config/initializers/25_carrierwave.rb @@ -9,4 +9,8 @@ CarrierWave.configure do |config| config.fog_credentials = APP_CONFIG.dig("fog", "credentials") unless APP_CONFIG.dig("fog", "credentials").nil? config.fog_directory = APP_CONFIG.dig("fog", "directory") unless APP_CONFIG.dig("fog", "directory").nil? end -end \ No newline at end of file +end + +CarrierWave::Backgrounder.configure do |c| + c.backend :sidekiq, queue: :carrierwave +end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 6da98de3..fd4423fd 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -7,7 +7,7 @@ production: :concurrency: 25 :queues: - share - - paperclip + - carrierwave - mailers - deletion - question diff --git a/db/schema.rb b/db/schema.rb index 67d6ad34..499d010e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_05_13_154602) do +ActiveRecord::Schema.define(version: 2020_05_09_094402) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -250,7 +250,7 @@ ActiveRecord::Schema.define(version: 2020_05_13_154602) do t.text "bio", default: "", null: false t.string "profile_picture_file_name" t.string "profile_picture_content_type" - t.bigint "profile_picture_file_size" + t.integer "profile_picture_file_size" t.datetime "profile_picture_updated_at" t.boolean "profile_picture_processing" t.integer "crop_x" @@ -267,7 +267,7 @@ ActiveRecord::Schema.define(version: 2020_05_13_154602) do t.integer "comment_smiled_count", default: 0, null: false t.string "profile_header_file_name" t.string "profile_header_content_type" - t.bigint "profile_header_file_size" + t.integer "profile_header_file_size" t.datetime "profile_header_updated_at" t.boolean "profile_header_processing" t.integer "crop_h_x"