From 01006ec77176d2f8e2601e616464ea6529b33a95 Mon Sep 17 00:00:00 2001 From: Nastia Gorokhova-Alekseeva Date: Tue, 11 Apr 2023 18:29:46 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20after?= =?UTF-8?q?=5Fcommit,=20=D0=B0=20=D0=BD=D0=B5=20=D0=B2=20after=5Fsave?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/paperclip.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip.rb b/lib/paperclip.rb index cf2e5e0..947c832 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -220,7 +220,7 @@ module Paperclip attachment_definitions[name] = Attachment.build_class(name, options) const_set("#{name}_attachment".camelize, attachment_definitions[name]) - after_save :save_attached_files + after_commit :save_attached_files after_commit :destroy_attached_files, on: :destroy after_commit :flush_attachment_jobs From 9014ae392075b32b288e6c9b6bdd6290d89dd372 Mon Sep 17 00:00:00 2001 From: Vladislav-S Date: Mon, 15 May 2023 21:59:50 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D1=87=D0=B8=D0=BD=D0=B8=D0=BC=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/paperclip.rb | 5 ++++- lib/paperclip/storage/no_cache_s3.rb | 2 +- test/storage/cached_test.rb | 1 + test/storage/no_cache_s3_test.rb | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/paperclip.rb b/lib/paperclip.rb index 947c832..e61d7c3 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -315,8 +315,11 @@ module Paperclip def save_attached_files logger.info("[paperclip] Saving attachments.") - each_attachment do |_name, attachment| + each_attachment do |name, attachment| attachment.send(:save) + # переехало сюда из delayed_paperclip process_in_background. нужно чтобы порядок загрузки - обработки + # не поломало + enqueue_delayed_processing if attachment_definitions[name][:delayed].present? end end diff --git a/lib/paperclip/storage/no_cache_s3.rb b/lib/paperclip/storage/no_cache_s3.rb index 9fb56d3..e8d8653 100644 --- a/lib/paperclip/storage/no_cache_s3.rb +++ b/lib/paperclip/storage/no_cache_s3.rb @@ -183,7 +183,7 @@ module Paperclip # ignore deleted objects and skip callbacks return if instance.class.unscoped.where(id: instance.id).update_all(synced_field_name => true) != 1 - instance.touch + instance.updated_at = Time.current if instance.respond_to?(:updated_at=) instance[synced_field_name] = true end diff --git a/test/storage/cached_test.rb b/test/storage/cached_test.rb index 4be6957..75f621c 100644 --- a/test/storage/cached_test.rb +++ b/test/storage/cached_test.rb @@ -70,6 +70,7 @@ class CachedStorageTest < Test::Unit::TestCase should 'write to permanent stores and clear cache' do @instance.update!(avatar: stub_file('test.txt', 'qwe')) + @instance.run_callbacks(:commit) @instance.reload attachment = @instance.avatar key = attachment.key diff --git a/test/storage/no_cache_s3_test.rb b/test/storage/no_cache_s3_test.rb index ec819ae..2d85431 100644 --- a/test/storage/no_cache_s3_test.rb +++ b/test/storage/no_cache_s3_test.rb @@ -61,6 +61,7 @@ class NoCacheS3Test < Test::Unit::TestCase @store1_stub.expects(:put_object).once @store2_stub.expects(:put_object).never @instance.update!(avatar: stub_file('test.txt', 'qwe')) + @instance.run_callbacks(:commit) @instance.reload attachment = @instance.avatar assert_equal 'http://store.local/test.txt', attachment.url(:original, false) @@ -74,6 +75,7 @@ class NoCacheS3Test < Test::Unit::TestCase @store1_stub.expects(:put_object).once @store2_stub.expects(:put_object).once @instance.update!(avatar: stub_file('test.txt', 'qwe')) + @instance.run_callbacks(:commit) @instance.reload attachment = @instance.avatar assert_equal 'http://store.local/test.txt', attachment.url(:original, false)