attachment_fu:不要重新加载缩略图 [英] attachment_fu: Don't reload thumbnails
问题描述
我有一个很好的小照片"类,上面附有图像.当我转到页面对照片的顺序进行排序时,它会遍历每张照片,设置新的"sort"值,然后保存它.到目前为止一切都很好.
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.
问题是,我注意到这种行为相当缓慢.事实证明,无论是否有新的图像数据要使用,attachment_fu都会在每次保存时重新加载缩略图.
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.
显然,此系统已经过周密的考虑,因此我仅假设存在针对这种情况的规定.如何在不合适的情况下告诉attachment_fu不要重新生成缩略图?
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?
谢谢,-Matchu
我刚刚记得,对于这种特殊情况,我可以使用update_attribute躲避所有验证和其他回调.但是,这并不是解决整个大问题的切实可行的答案.我想念什么?
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?
推荐答案
稍微进来并侵入了attach_fu,然后重写了save_attachment?
行为.几乎,我添加了一些新条件:除了现有的临时文件之外,还必须满足以下条件之一:
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:
- 不存在用于图像的文件(使用
full_filename
属性). - 使用
uploaded_data=
方法显式更新了图像数据. - 图像是缩略图.
- No file for the image already exists (using the
full_filename
attribute). - The image data was explicitly updated using the
uploaded_data=
method. - 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.
这篇关于attachment_fu:不要重新加载缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!