Posted almost 9 years ago. Visible to the public.

Reprocess only missing images with Paperclip

When a paperclip attachment gains a new style and you have many attachments, reprocessing can take ages. This is because all styles are being recomputed.

To create only missing images, patch Paperclip like this in your script that does the reprocessing:

Paperclip <2.3.2

Copy
class Paperclip::Attachment private def post_process_styles_with_extreme_lazyness @old_styles = @styles @styles = @styles.reject do |name, _| exists?(name) end post_process_styles_without_extreme_lazyness ensure @styles = @old_styles end alias_method_chain :post_process_styles, :extreme_lazyness end

Paperclip >= 2.3.2 (untested):

Copy
class Paperclip::Attachment private def post_process_styles_with_extreme_lazyness styles @old_styles = @normalized_styles @normalized_styles = @normalized_styles.reject do |name, _| exists?(name) end post_process_styles_without_extreme_lazyness ensure @normalized_styles = @old_styles end alias_method_chain :post_process_styles, :extreme_lazyness end

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Tobias Kraze
Last edit:
almost 9 years ago
Keywords:
faster, fast, slow
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Tobias Kraze to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more