Module: Spree::Image::ActiveStorageAttachment
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveStorageAdapter
- Defined in:
- app/models/spree/image/active_storage_attachment.rb
Class Method Summary collapse
-
.attachment_preloads ⇒ Object
Returns the preload tree needed to resolve image.url(style) and image.alt without N+1 queries.
Methods included from ActiveStorageAdapter
#default_style, #destroy_attachment, #filename, #styles, #url
Methods included from ActiveStorageAdapter::Normalization
Class Method Details
.attachment_preloads ⇒ Object
Returns the preload tree needed to resolve image.url(style) and image.alt without N+1 queries. Used by callers to nest preloads under image-bearing associations on parent records, e.g. includes(variant_images: Spree::Image.attachment_preloads)
We build this manually rather than delegating to with_attached_attachment because Rails' generated scope includes a preview_image_attachment branch that is only relevant for non-image files (PDFs, videos, etc.). Product images never have previews, so including that branch loads empty result sets from active_storage_attachments and active_storage_blobs on every request for no benefit.
36 37 38 |
# File 'app/models/spree/image/active_storage_attachment.rb', line 36 def self. = [ {attachment_attachment: {blob: {variant_records: {image_attachment: :blob}}}} ] |