ruby-on-railsruby-on-rails-5rails-activestorage

How to disable ActiveStorage Analyzers and Previewers


I have a Rails 5.2.3 app using ActiveStorage. By default, ActiveStorage would run some background jobs to extract metadata from attached files, and/or create thumbnail images for previews.

I don't want that. I don't need any metadata, nor do I need any thumbnails. So how can I disable these background jobs?

According to the official Rails guide, I've set

config.active_storage.analyzers = []
config.active_storage.previewers = []

in /config/application.rb.

However, looks like it doesn't help. When running rails test, I still see

[ActiveJob] [ActiveStorage::AnalyzeJob] Performing ActiveStorage::AnalyzeJob (Job ID: 741592f5-c5e4-48d7-8cf9-158790fb8a00) from Inline(default) with arguments: #<GlobalID:0x00005642f9050748 @uri=#<URI::GID >>
[ActiveJob] [ActiveStorage::AnalyzeJob] (22.0ms)  SAVEPOINT active_record_1
[ActiveJob] [ActiveStorage::AnalyzeJob] ActiveStorage::Blob Update (22.7ms)  UPDATE `active_storage_blobs` SET `metadata` = '{\"identified\":true,\"analyzed\":true}' WHERE `active_storage_blobs`.`id` = 3056
[ActiveJob] [ActiveStorage::AnalyzeJob] (21.9ms)  RELEASE SAVEPOINT active_record_1   

I've also tried via an initializer file:

# /config/initializers/active_storage_disable_analyze.rb
Rails.application.config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer
Rails.application.config.active_storage.analyzers.delete ActiveStorage::Analyzer::VideoAnalyzer

But this doesn't help neither.


Solution

  • There is no easy way to disable Analyzers completely. Rails falls back to NullAnalyzer when you delete the Image/Video analyzers, which doesn't gather any metadata.

    You can see where it defaults here