Handling in-progress ActiveStorage variants

Hello all, I am working on a specific use case with ActiveStorage and I want to be sure I’m not missing an obvious easy way to do it.

I am working on a rails application that uses ActiveStorage for attachments / variants. The application needs to accept pretty large images (e.g. 250mb+ JPEGs), and the app has a page that display thumbnails of uploaded images. When a user uploads an image, they are redirected back to that thumbnail listing page. I have specified preprocessed: true on the thumb variant, and I can see that an activejob gets queued and started to create the thumbnail. However, calling photo.file.variant(:thumb).processed.url runs the processed method found here:

That method determines (correctly) that the variant has not yet been processed, because the active job is still running, so it attempts to create the variant inline with the request. This is what I’m trying to avoid, since at best it results in a very slow server response.

I looked around in that class, and it has a private processed? method that looked useful. I tried using that locally (naughty I know) and I was able to build a helper method that would display a placeholder image for these in-progress variants. Success!

# app/helpers/application_helper.rb
def variant_or_placeholder_url(variant)
  if variant.send(:processed?)
    variant.processed.url
  else
    asset_url("icons/variant_placeholder.svg")
  end
end

# app/views/photos/_photo.html.haml
= image_tag variant_or_placeholder_url(photo.file.variant(:thumb))

Does this seem useful enough to warrant making ActiveStorage::Variant#processed? public? I’m happy to open a PR for that, but since I found no talk about this subject at all I’m not sure if anyone else would find it helpful.