File tree Expand file tree Collapse file tree 6 files changed +20
-4
lines changed
app/models/active_storage Expand file tree Collapse file tree 6 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class ActiveStorage::Attachment < ActiveStorage::Record
24
24
# :method:
25
25
#
26
26
# Returns the associated record.
27
- belongs_to :record , polymorphic : true , touch : true
27
+ belongs_to :record , polymorphic : true , touch : ActiveStorage . touch_attachment_records
28
28
29
29
##
30
30
# :method:
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ class ActiveStorage::Blob < ActiveStorage::Record
47
47
self . service_name ||= self . class . service &.name
48
48
end
49
49
50
- after_update :touch_attachment_records
50
+ after_update :touch_attachments
51
51
52
52
after_update_commit :update_service_metadata , if : -> { content_type_previously_changed? || metadata_previously_changed? }
53
53
@@ -376,8 +376,14 @@ def service_metadata
376
376
end
377
377
end
378
378
379
- def touch_attachment_records
380
- attachments . includes ( :record ) . each do |attachment |
379
+ def touch_attachments
380
+ attachments . then do |relation |
381
+ if ActiveStorage . touch_attachment_records
382
+ relation . includes ( :record )
383
+ else
384
+ relation
385
+ end
386
+ end . each do |attachment |
381
387
attachment . touch
382
388
end
383
389
end
Original file line number Diff line number Diff line change @@ -354,6 +354,7 @@ module ActiveStorage
354
354
mattr_accessor :unsupported_image_processing_arguments
355
355
356
356
mattr_accessor :service_urls_expire_in , default : 5 . minutes
357
+ mattr_accessor :touch_attachment_records , default : true
357
358
mattr_accessor :urls_expire_in
358
359
359
360
mattr_accessor :routes_prefix , default : "/rails/active_storage"
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ class Engine < Rails::Engine # :nodoc:
110
110
ActiveStorage . variable_content_types = app . config . active_storage . variable_content_types || [ ]
111
111
ActiveStorage . web_image_content_types = app . config . active_storage . web_image_content_types || [ ]
112
112
ActiveStorage . content_types_to_serve_as_binary = app . config . active_storage . content_types_to_serve_as_binary || [ ]
113
+ ActiveStorage . touch_attachment_records = app . config . active_storage . touch_attachment_records != false
113
114
ActiveStorage . service_urls_expire_in = app . config . active_storage . service_urls_expire_in || 5 . minutes
114
115
ActiveStorage . urls_expire_in = app . config . active_storage . urls_expire_in
115
116
ActiveStorage . content_types_allowed_inline = app . config . active_storage . content_types_allowed_inline || [ ]
Original file line number Diff line number Diff line change @@ -25,4 +25,8 @@ class ActiveStorage::EngineTest < ActiveSupport::TestCase
25
25
test "image/bmp is a default content type" do
26
26
assert_includes ActiveStorage . variable_content_types , "image/bmp"
27
27
end
28
+
29
+ test "true is the default touch_attachment_records value" do
30
+ assert_equal true , ActiveStorage . touch_attachment_records
31
+ end
28
32
end
Original file line number Diff line number Diff line change @@ -2848,6 +2848,10 @@ The default is 5 minutes.
2848
2848
2849
2849
Determines the default expiry of URLs in the Rails application generated by Active Storage . The default is nil .
2850
2850
2851
+ # ### `config.active_storage.touch_attachment_records`
2852
+
2853
+ Directs ActiveStorage ::Attachments to touch its corresponding record when updated. The default is true .
2854
+
2851
2855
# ### `config.active_storage.routes_prefix`
2852
2856
2853
2857
Can be used to set the route prefix for the routes served by Active Storage . Accepts a string that will be prepended to the generated routes.
You can’t perform that action at this time.
0 commit comments