ActiveStorage - has_one_attached ... analyze: false

I’m dealing with a bunch of large-ish video files. I upload them directly to S3 and then attach to my VideoEdit record.

I don’t need the info that the AnalyseJob would provide, and downloading large files from S3 is unnecessary work/cost.

What’s the best way to disable analysis for a single attachment?

Claude and ChatGPT are convinced that I can do

has_one_attached :video, analyze: false

This seems to be a hallucination - but I wonder if it indicates an approach that people are taking in real life?

My current approach is

  def video=(attachable)
    # Call the original method to set the attachment
    super

    # Mark as analyzed to prevent analysis jobs
    if video.attached? && video.blob.present? && !video.blob.analyzed?
      video.blob.update!(analyzed: true)
    end
  end

which isn’t terrible, but it is getting into the implementation details.

any suggestions?

fwiw I asked my chatgpt for a second opinion :slight_smile:

I’d avoid setting analyzed: true directly if possible. It prevents the job, but it also makes the blob look like it was actually analyzed, which could get confusing if other code later relies on that state.

A no-op analyzer for this class of files feels cleaner if the main goal is to avoid downloading large videos for metadata you don’t use. The analysis job may still get enqueued, but it should do almost no work.

If the requirement is specifically to never enqueue analysis for this attachment, has_one_attached doesn’t currently provide an analyze: false option. That seems to be the actual API gap here.