From 57608d9f38b5f886bf05003aa8e1ad5d59871ea4 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Thu, 24 Mar 2022 12:11:18 +0000 Subject: [PATCH] Add patch to ActiveStorage::Blob#delete Prevent deletion of variants. We don't currently use variants and this causes timeouts (when doing a remote globs to find variant files to be deleted) when using a ActiveStorage SFTP service. See: https://github.com/rails/rails/blob/6-1-stable/activestorage/app/models/active_storage/blob.rb#L287-L290 --- lib/model_patches.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/model_patches.rb b/lib/model_patches.rb index bbeb0033..34b40757 100644 --- a/lib/model_patches.rb +++ b/lib/model_patches.rb @@ -134,4 +134,14 @@ def disable prepend DisableWithProtection end + + ActiveStorage::Blob.class_eval do + def delete + service.delete(key) + # Prevent deletion of variants. We don't currently use variants and this + # causes timeouts (when doing a remote globs to find variant files to be + # deleted) when using a ActiveStorage SFTP service + # service.delete_prefixed("variants/#{key}/") if image? + end + end end