Read more

Reprocess only missing images with Paperclip

Tobias Kraze
August 25, 2010Software engineer at makandra GmbH

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.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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

Paperclip <2.3.2

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):

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
Posted by Tobias Kraze to makandra dev (2010-08-25 16:03)