Immediate avatar and embed variants

Process variants synchronously on attachment to close the window between
image upload and variant availability, guaranteeing that we won't have
lazy variant processing attempts in GET requests.

Tradeoff is that we do variant processing in upload requests, which is
actually desirable. We're working with images that should take
milliseconds to resize given that we'll already have the file on hand.

References https://github.com/rails/rails/pull/51951
This commit is contained in:
Jeremy Daer
2025-12-04 23:17:21 -08:00
parent d729cf59f9
commit 21f3f72647
9 changed files with 59 additions and 17 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ module User::Avatar
included do
has_one_attached :avatar do |attachable|
attachable.variant :thumb, resize_to_fill: [ 256, 256 ]
attachable.variant :thumb, resize_to_fill: [ 256, 256 ], process: :immediately
end
validate :avatar_content_type_allowed