Rails:如何禁用 ActiveStorage 分析器和预览器 [英] Rails: How to disable ActiveStorage Analyzers and Previewers

查看:25
本文介绍了Rails:如何禁用 ActiveStorage 分析器和预览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ActiveStorage 的 Rails 5.2.3 应用程序.默认情况下,ActiveStorage 会运行一些后台作业来从附加文件中提取元数据,和/或创建缩略图以供预览.

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?

根据 官方 Rails 指南,我已经设置

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

/config/application.rb 中.

然而,看起来它没有帮助.在运行 rails test 时,我仍然看到

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

但这也无济于事.

推荐答案

没有简单的方法可以完全禁用分析器.Rails 回退到 NullAnalyzer 时您删除不收集任何元数据的图像/视频分析器.

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

这篇关于Rails:如何禁用 ActiveStorage 分析器和预览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆