Search code examples
ruby-on-railsattachment-fu

attachment_fu: Don't reload thumbnails


I've got a nice little "photos" class that has attached images. When I go to the page to sort the photos' order, it iterates though each photo, sets the new "sort" value, and saves it. All good so far.

Problem is, I've noticed this behavior is fairly slow. Turns out, attachment_fu reloads the thumbnail on every save - regardless of whether or not there's new image data to work with.

Obviously this system has been well-thought-out, so I'm only left to assume that a provision exists for this situation. How do I tell attachment_fu not to regenerate the thumbnails when it's not appropriate?

Thanks, --Matchu

Edit: I just remembered that, for this particular situation, I can use update_attribute to dodge all the validations and other callbacks. However, this isn't really a viable answer to the whole big scenario. What am I missing?


Solution

  • Went in and hacked attachment_fu a bit, and rewrote the save_attachment? behavior. Pretty much, I added some new conditions: in addition to a temp file existing, one of the following must be true:

    1. No file for the image already exists (using the full_filename attribute).
    2. The image data was explicitly updated using the uploaded_data= method.
    3. The image is a thumbnail.

    It passes all three test cases - new photo uploads, edit photo images, and editing non-image photo data - but I haven't really tested this out in the wild just yet. I'll probably have to make a few fixes; we'll see what happens.