From 143508fc221c6a28864153a1ac046b4f4ffc3d8d Mon Sep 17 00:00:00 2001 From: Joseph Hale Date: Mon, 2 Mar 2026 14:13:00 -0700 Subject: [PATCH] Skip AnalyzeJob when blob has no attachments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upload-then-delete races cause AnalyzeJob to hit S3 after PurgeJob has already removed the object, producing Aws::S3::Errors::NoSuchKey noise in solid_queue_failed_executions. Since PurgeOnLastAttachment destroys the attachment row before enqueueing PurgeJob, checking blob.attachments.exists? catches this — a fast DB query that avoids the S3 round-trip entirely. Co-Authored-By: Claude Opus 4.6 --- ...storage_analyze_job_suppress_broadcasts.rb | 2 ++ ...ge_analyze_job_suppress_broadcasts_test.rb | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts_test.rb diff --git a/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb b/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb index ba22603b6..030232ee4 100644 --- a/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb +++ b/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts.rb @@ -4,6 +4,8 @@ # there is currently a bug https://github.com/rails/rails/issues/55144 module ActiveStorageAnalyzeJobSuppressBroadcasts def perform(blob) + return unless blob.attachments.exists? + Board.suppressing_turbo_broadcasts do Card.suppressing_turbo_broadcasts do super diff --git a/test/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts_test.rb b/test/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts_test.rb new file mode 100644 index 000000000..1015c957c --- /dev/null +++ b/test/lib/rails_ext/active_storage_analyze_job_suppress_broadcasts_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class ActiveStorageAnalyzeJobSuppressBroadcastsTest < ActiveSupport::TestCase + test "skips analysis when blob has no attachments" do + blob = ActiveStorage::Blob.create_and_upload!( + io: StringIO.new("x" * 1024), filename: "orphan.txt", content_type: "text/plain" + ) + + blob.expects(:analyze).never + + ActiveStorage::AnalyzeJob.perform_now(blob) + end + + test "performs analysis when blob has attachments" do + card = cards(:logo) + card.image.attach io: StringIO.new("x" * 1024), filename: "test.png", content_type: "image/png" + blob = card.image.blob + + blob.expects(:analyze).once + + ActiveStorage::AnalyzeJob.perform_now(blob) + end +end