Skip to content

Commit

Permalink
Merge pull request #2342 from tvdeyen/pre-generate-thumbs-ingredients
Browse files Browse the repository at this point in the history
Add task to eagerly generate ingredients pictures thumbnails
  • Loading branch information
tvdeyen committed May 30, 2022
1 parent 196243a commit 114187d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/tasks/alchemy/thumbnails.rake
Expand Up @@ -35,5 +35,29 @@ namespace :alchemy do

puts "Done!"
end

desc "Generates thumbnails for Alchemy Picture Ingredients (set ELEMENTS=element1,element2 to only generate thumbnails for a subset of elements)."
task ingredient_picture_thumbnails: :environment do
ingredient_pictures = Alchemy::Ingredients::Picture.
joins(:element).
preload({ related_object: :thumbs }).
merge(Alchemy::Element.available)

if ENV["ELEMENTS"].present?
ingredient_pictures = ingredient_pictures.merge(
Alchemy::Element.named(ENV["ELEMENTS"].split(","))
)
end

puts "Regenerate #{ingredient_pictures.count} ingredient picture thumbnails."
puts "Please wait..."

ingredient_pictures.find_each do |ingredient_picture|
puts ingredient_picture.picture_url
puts ingredient_picture.thumbnail_url
end

puts "Done!"
end
end
end

0 comments on commit 114187d

Please sign in to comment.